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):
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)
Any help is greatly appreciated! Any questions just ask
Code Snippet to Uncheck the Display on Order Open checkbox on notes
-
- Posts: 23
- Joined: Wed Jul 12, 2023 11:29 am
Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes
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.
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
Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes
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.
-
- Posts: 23
- Joined: Wed Jul 12, 2023 11:29 am
Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes
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.
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.
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
Re: Code Snippet to Uncheck the Display on Order Open checkbox on notes
Thank you Paul! Works like a charm. I appreciate the info and your patience. Thanks again!