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
12-05-2017 05:50 AM
Hi Steven,
Related list records are all about the reference field on there list record and how it relates to the parent record you are viewing. You didn't provide any technical details (tables, fields, related list name, etc.) or actual business requirements so it's tough to provide any direction on a technical solution.
In general, if I have a record, say user, and want to delete an entry from Groups, it's important to three pieces of information.
- The current record's table and sys_id
- The related list record's table and sys_id
- The reference field from the related record to the current record
The script would go something like this:
var rel = new GlideRecord('sys_user_grmember');
if (rel.get('related_related_record_sys_id')) {
// Do your processing here, e.g. rel.deleteRecord()
}
You could put that in a business rule, or workflow script (in your case) as needed - don't forget to adjust where necessary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 05:56 AM
Sorry about that Chuck...guess I could have provided more details.
I've created a related list on the User form which references our custom Application table:
Essentially what I want to do is either add or remove an application from that list via our Access Request workflow. So if someone chooses a user and "Add Acces" and Excel for example...then go to that User Record and update this related list with Excel. Or if it's a "Remove Access" request then remove it from the related list.
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
12-05-2017 06:05 AM
Hi Steven,
You can insert a record in m2m table using GlideRecord, in case you checked it, Delete it in case it is Remove Access.
Please create a Business Rule and run the scripts which will fulfillment your requirements.
Insert -> true
Table -> Request Item
Filter Condition -> item is <Item Name>
if(current.variables.<variable name for access type> == <ADD Drop Down Value>)
script to INSERT --> http://wiki.servicenow.com/index.php?title=GlideRecord#Insert_Methods
else if(current.variables.<variable name for access type> == <REMOVE Drop Down Value>)
script to DELETE ---> http://wiki.servicenow.com/index.php?title=GlideRecord#Delete_Methods&gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 06:18 AM
Hi Steven,
could you please clarify what do you mean when you say "Access Request workflow" ? - is that special type of procedure? or you meant something else?