Run Script to Add/Delete on Related List

Steven Parker
Giga Sage

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
23 REPLIES 23

"Access Request" is just a workflow we've built and use in our Instance.   It's where people request to add or remove access to certain applications.



Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

So if that is workflow - there is "Run Script" activity that you may leverage to add/remove records to desired related list


So this gets me to the user record on the sys_user table:


find_real_file.png


This is the related list on the user record:



u_founders_application_list.u_user_access



So now I am trying to figure out how to reference this related list and ensure I am on the correct user record.



Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

So, if I understand you correct - there is custom table named "Founders Application List" [ u_founders_application_list ] that has Reference field to User [ sys_user ] table named "User Access".



If that is correct, in your Run Script activity you need to either generate new record for this table or remove existing - depends on your need to Add or remove.



For Example,


in case if you need to add new record to Related table, in you activity you need to do something like following:



var gr = new GlideRecord('u_founders_application_list'); // this will create Glide Record object


gr.initialize(); // this is required to initialize new record


gr.u_user_access = gs.getUserID() // here you need replace gs.getUserID() with value of user's sys_id that you want to add


gr.insert(); // creating new record



simple like that - may be this is not exact code that you need - but this will provide you with idea and direction of how what should be your next actions.


Andrii



I am not trying to add any new records to that Founders Application List table.



What I am trying to do is on the user's record, update the related list on that record with the application they were granted access to:



find_real_file.png


So basically here, I can manually click edit, choose Excel for example, and then excel would show as an Application that Abbe has access too.   I am trying to update that related list using a Run Script.   I can easily connect to the User record like this:



find_real_file.png


But I don't know how to connect to that Related List and add(Edit...) an item to it via a script.



Please mark this response as correct and/or helpful if it assisted you with your question.
Steven