- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2021 10:44 PM
Hello,
I have a List Collector variable on the RITM.
Users can select name from the List Collector. If selected name listed as an approver and state is approved, display a message and remove the name from the List Collector. I appreciate the help.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2021 09:33 AM
Make sure you have checked 'Applies to a Requested Item'.
You can use below logic in your client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var RITM = g_form.getUniqueValue();
var myList = newValue;
var myArray = myList.split(',');
var result = [];
for (var i = 0; i < myArray.length; i++) {
var sysapproval = new GlideRecord('sysapproval_approver');
sysapproval.addQuery('sysapproval', RITM);
sysapproval.addQuery('approver', myArray[i].toString());
sysapproval.addQuery('state', 'approved');
sysapproval.query();
if (!sysapproval.next()) {
result.push(myArray[i].toString());
}
}
if (myArray.toString() != result.toString()) { // to avoid reccusrsive calls
g_form.setValue('attendeeName', result.toString());
}
}
With this script you will observer some performance issue if add more users from list.
I would suggest to use GlideAjax and get the result from server. It would be more efficient.
Pleas find below Ho you can use GlideAjax:
Pass myList and RITM id as parameters to and use below part of client script in Script include to get result:
var myArray = myList.split(',');
var result = [];
for (var i = 0; i < myArray.length; i++) {
var sysapproval = new GlideRecord('sysapproval_approver');
sysapproval.addQuery('sysapproval', RITM);
sysapproval.addQuery('approver', myArray[i].toString());
sysapproval.addQuery('state', 'approved');
sysapproval.query();
if (!sysapproval.next()) {
result.push(myArray[i].toString());
}
}
I don't mine sharing complete script, but that would server the purpose only. I would be more happy if you try it by yourself. It would be useful in future as well. Happy Learning 🙂
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2021 10:28 PM
Hi,
ok when user updates the list collector variable and if one of the user is the approver who already approved the RITM then you need to stop the update operation?
Is the understanding correct?
If yes then you can use before update BR on RITM table
1) get the variable values
2) check any of the user in the list collector is in the approver of the RITM which is already approved
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2021 09:20 PM
Ankur,
I'm a beginner at scripting. I have spent many hours trying to get this to work, but I didn't get anywhere. Could you please help?
If it is possible, we would like to trigger when the list collector onChange? Here's what I have so far and I know it is incorrect. I hope you can provide suggestions. Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2021 09:33 AM
Make sure you have checked 'Applies to a Requested Item'.
You can use below logic in your client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var RITM = g_form.getUniqueValue();
var myList = newValue;
var myArray = myList.split(',');
var result = [];
for (var i = 0; i < myArray.length; i++) {
var sysapproval = new GlideRecord('sysapproval_approver');
sysapproval.addQuery('sysapproval', RITM);
sysapproval.addQuery('approver', myArray[i].toString());
sysapproval.addQuery('state', 'approved');
sysapproval.query();
if (!sysapproval.next()) {
result.push(myArray[i].toString());
}
}
if (myArray.toString() != result.toString()) { // to avoid reccusrsive calls
g_form.setValue('attendeeName', result.toString());
}
}
With this script you will observer some performance issue if add more users from list.
I would suggest to use GlideAjax and get the result from server. It would be more efficient.
Pleas find below Ho you can use GlideAjax:
Pass myList and RITM id as parameters to and use below part of client script in Script include to get result:
var myArray = myList.split(',');
var result = [];
for (var i = 0; i < myArray.length; i++) {
var sysapproval = new GlideRecord('sysapproval_approver');
sysapproval.addQuery('sysapproval', RITM);
sysapproval.addQuery('approver', myArray[i].toString());
sysapproval.addQuery('state', 'approved');
sysapproval.query();
if (!sysapproval.next()) {
result.push(myArray[i].toString());
}
}
I don't mine sharing complete script, but that would server the purpose only. I would be more happy if you try it by yourself. It would be useful in future as well. Happy Learning 🙂
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2021 09:39 PM
You guys are awesome! Without your assistance, it would’ve taken me weeks to figure out.
Can you recommend some beginner scripting courses? Also, how can I show a message with selected name displays.
Thank you so much for sharing your knowledge. I really appreciate your help
Lisa

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2021 10:17 PM
Hi Lisa,
Glad to resolve your issue.
You can check below course:
Also I would suggest you to keep eye on community threads which you find familiar. You can find problem statement as well as solutions provided. You can try these scenarios on your personal instance and improve your scripting skill.
Thanks,
Anil Lande
Thanks
Anil Lande