Code Snippet to Uncheck the Display on Order Open checkbox on notes

Questions about and code samples for automation process code snippets within Select.
Post Reply
alenzie
Posts: 3
Joined: Tue Jan 23, 2024 8:38 pm

Code Snippet to Uncheck the Display on Order Open checkbox on notes

Post by alenzie »

Hi there!

I need help creating a code snippet.

I have created an automation for a code snippet to run after a certain task is completed. (Screenshot below):
Automation.png
Automation.png (29.78 KiB) Viewed 772 times
The code snippet needs to access the order and on order open click the "Do not display messages again" checkbox in the prompt. Then "OK" on the next prompt. (Screenshots below)
Note.png
Note.png (12.96 KiB) Viewed 772 times
Alert Confirmation.png
Alert Confirmation.png (13.6 KiB) Viewed 772 times
Any help is greatly appreciated! Any questions just ask :)
PaulMcCullough
Posts: 23
Joined: Wed Jul 12, 2023 11:29 am

Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes

Post by PaulMcCullough »

The automation scripts run in the background on the server after order is saved. Because of this, there is no way for them to interact with the user interface.

However, there is a way to control whether or not a note is displayed when the order is opened. Since your script is triggered by a Task being added or updated, the Context will be set to that Task. You can iterate through all of the Notes attached to that Task and set DisplayOnOrderOpen = False. The code snippet below should work.

Code: Select all

	for note in Context.Notes:
		note.DisplayOnOrderOpen = False
alenzie
Posts: 3
Joined: Tue Jan 23, 2024 8:38 pm

Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes

Post by alenzie »

Thank you Paul! The notes are not tied to a task but rather them being completed triggers the code snippet to run through and uncheck the display on open order. IS the task context necessary. I am new to this and am having trouble with the iteration portion as well. Again thank you for your help.
PaulMcCullough
Posts: 23
Joined: Wed Jul 12, 2023 11:29 am

Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes

Post by PaulMcCullough »

I was only mentioning the Task context because the screenshot of your automation process shows it is triggered by "First time a task is added or updated". Since your script is triggered by a Task, the Context object will be set to the Task that was added or updated.

If you want to get to the Order for that Task you can use Context.Root. So from this script, if you want to prevent all the notes on the Order from being displayed when the Order opens, you can use the following code.

Code: Select all

for note in Context.Root.Notes:
	note.DisplayOnOrderOpen = False
By iteration I just mean going through each item in a collection (in this case, the collection of Notes) and doing something with each one. That's what the for loop does.
alenzie
Posts: 3
Joined: Tue Jan 23, 2024 8:38 pm

Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes

Post by alenzie »

Thank you Paul! Works like a charm. I appreciate the info and your patience. Thanks again!
Post Reply