The CreatorCon Call for Content is officially open! Get started here.

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 

Good morning Anil,

I have tried both ways, but somehow I could not get OR condition to work and I cannot spot where I made the mistake.

 

find_real_file.png

Hi Lisa,

Can you please share what you are trying to achieve and share your complete script. Also share what you are getting with above 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

@Anil Lande 

Good morning Anil,

On the RITM, we have a List Collector variable where Fulfiller can add Attendee Name to the List Collector.  

The code should be checking the List Collector against the approval record to see if the added Attendee Name is one of the existing approver with the state of either "Approved" Or "Requested". 

If there is, the code should be remove them from the List Collector.

The below screenshot is from PDI. The company instance has the same setup.

 

find_real_file.png

 

A few months back, you were helping me with the below code and it is working great, because we only have a few users to add. Therefore, we won't run into performance issue.

 However, the exiting code only check for state with "Approved". I need to modify to code to also look for state with "Requested".

I have spent many late night trying figure this out, but no luck.

Here is the original code that you shared.  Thank you so much Anil.

 

find_real_file.png

 

Hi,

Yeah I got it now now.

Please update the line like below:

find_real_file.png

 

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

Also check if you can alter your client script and make use of GlideAjax to get data from server side.

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

 

Please mark all appropriate answers as helpful if they help you to to resolve your issue.

 

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