- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 11:53 PM - edited 10-18-2023 11:58 PM
Hi Team,
I want to populate Approvers list in custom field on RITM. I have wrote below BR on RITM table after- insert/update.
Users are not populating, not sure what's wrong. custom field is glide list type.
Condition: current.approval.changesTo('requested')
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.query();
var myString='';
if(gr.hasNext()){
while(gr.next()){
myString = myString +gr.approver+',';
gs.log(current.number+' Inside while loop Approval List ='+myString);
}
myString=myString.slice(0, -1);
gs.log(current.number+' Outside while loop Approval List ='+myString);
current.u_approvers=myString;
gs.log(current.number+' Outside while loop current.u_approvers ='+current.u_approvers);
current.update();
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 03:06 AM
1) In the BR condition you can add a condition (first tab where we mentioned the condition in builder)
-> u_approvers is empty
2) please make BR to before-> insert/update
3) Remove current.update()
current.update() is fine for after insert but creates problem for after update
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 04:10 AM
Your BR should be on Approval table but the answer you marked as correct says the BR should be on RITM table which is wrong.
Could you please ensure you mark appropriate response as correct so that it doesn't confuse users in future?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 12:39 AM
your BR should be on sysapproval_approver table and not RITM
BR: After Insert
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.sysapproval);
gr.query();
if(gr.next()){
if(gr.u_approvers == '')
gr.u_approvers = current.approver;
else
gr.u_approvers = gr.u_approvers + ',' + current.approver;
gr.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 12:56 AM
Hi Ankur,
Above script works but issue is it will keep on adding users to custom field, we have 1st level approver and 2 level approvers, once 1st level approvals are approved, need to clear value in custom field and update with new approvers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 04:08 AM
have after update BR on Approval table with state as Approved
Then search for that approver and remove it from that list
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 04:12 AM
You mentioned as per your original question to just add approvers and didn't mention to remove them once approved.
Also you mentioned that script I shared work fine.
Could you please mark my response as correct as that worked for you?
Thanks in advance
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader