List collector variable data comparison

Lisa Goldman
Kilo Sage

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.  

 

find_real_file.png

 

1 ACCEPTED SOLUTION

A@Lisa Goldman 

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:

https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...

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

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

21 REPLIES 21

Anil Lande
Kilo Patron

Hi,

An RITM will have variables which are filled on Catalog Item form. At that time the approval is not exist. So it is not possible to check selected user with the approvers.

 

If user is able to edit variable after RITM is generated the you can use onChange Catalog Client script and check 'Applies to a Requested Item' checkbox.

OnChange of list collector field make a GlideAjax call and in script include glide to Approval table and look for related approvals. If selected user is one of approver then remove that sys_id from array and return updated array. and set it to the field in client script.

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

The comparison is after RITM is approved, I need to check the approver name again the list collector.

Based on your suggestion,  it is very complicated.  I don't where to begin.  Could you please provide screenshots or samples so I can use it as a guide.  Thank you

Ankur Bawiskar
Tera Patron
Tera Patron

@Lisa Goldman 

Why to remove that user from list collector variable once RITM is approved by that user?

You should not remove/delete any data from any variable post RITM is created as it would lead to data discrepancy and would result in data loss.

Please check this with your business team on the requirement

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,

When approved RITM loaded, the list collector variable is empty.

Fulfiller can select the name from the list collector.  At this stage, the list collector data has not been saved to the database. 

The program should be checking to see if the selected name is one of the approver. if it is, remove the name from the list collector.

This is an Union special event and management is this case is Approvers are not allow to the event