Run Script to Add/Delete on Related List
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 05:44 AM
Anyone have any examples of adding/removing items from a related list via a Run Script in a workflow? I am not finding much in my Google searches and I have a related list on our sys_user records and I wanted to update via a Run Script in a workflow.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2018 11:29 AM
Thanks Steve!
I was finally able to figure out what I was doing wrong and model my script from yours. Thanks again for sharing.
-Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2018 11:45 AM
No problem..if you could mark one of the responses as the correct answer (or most correct answer) that would be helpful.
Thanks!
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2018 02:38 PM
Hi Steve,
It is your post, so I can't mark it as 'correct answer'. But I have tagged all your responses as "Helpful".
Another question for you? I struggle to know when I need to use 'function' declaration in a Workflow Run Script. I received some help on my current script that flowed more like yours but someone else said I need to add the following around my script. I notice my script works with or without it.
Do you have any guidance?
(function () {
})();
-Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 05:15 AM
I am probably not the best at explaining that, but this article does a decent job. It really involves the processing and whether it occurs synchronous or asynchronous. I add them far more in Client Scripts (Client scripts, by default, start wrapped in Function()) than Run Scripts. Although, I do know one specific example in a Run Script where I use a function within the run script to make each value in the array unique (remove duplicates). Outside of every client script being wrapped in them, I don't use Function() very often and in Run Scripts, I rarely use them.
https://www.servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven