- 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
09-02-2021 10:21 PM
You sure hit it on the nail Anil! You kick butt at coding!
I definitely will try to convert your code to GlideAjax in the near future, because I have so much ServiceNow issues that I need to resolve first.
The community has helped me enormously, however sometimes my posts never get answered. Thank you for your quick responses.
If I get stuck, I hope I can contact you for assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2021 07:59 PM
Hello @Anil Lande,
A while back you helped me with the client script to check against the List Collector variable value to see if it contains one of the name that approved the RITM. So far, it has been working very well.
However, you asked me to convert it to GlideAjax and get the result from server. It would be more efficient.
I tried with the following codes, but it doesn't seems to work. If you have time, please review the code and let me know what I did wrong so I can learn from you. Thank you.
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("TestGetApprover"); //Calling Script Include Name
ga.addParam("sysparm_name", " getApprover"); //calling script Include Function
ga.addParam("sysparm_ci", g_form.getValue('additional_approvers')); //Get List Collector Variable value
ga.getXML(ApproverdParse);
function ApproverdParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
Script Include:
var TestGetApprover = Class.create();
TestGetApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApprover: function() {
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());
}
}
},
type: 'TestGetApprover'
});