Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

to check two or more specific values in array

levino
Giga Guru

hi there

roleVar is a list of sys_ids.

roles is the specific sys_ids i want to check and if found do something.

 

when i try with the  first sys_id it evaluates correctly , but not with the second one, is the script below correct?

 

Thanks

Levino

 

 

 

 var roleVar = ritm.variables.secondary_access.toString();
    var roles = 'ea1d77f9dbf45110b8846c13059619e4,f96d773ddbf45110b8846c130596197c';



    for (var i = 0; i < roleVar.length; i++) {
        if (roles.indexOf(roleVar[i]) !== -1) 
{
//do somethin
}
11 REPLIES 11

Hi Ankur

on that catalog item i have another variable called  accees_required as per below, which i can use in my script.

 

question the hightlighted part is within quotes, does the script treat the 2 sys_ids as separate values? or do i need to amend my script

Thanks

Levino

 

["b1ce224fdb681cd018ca11b14a9619ac","ef9fa715db081c1818ca11b14a961957","22772fcddb04581818ca11b14a961975,ea1d77f9dbf45110b8846c13059619e4","e6772fcddb04581818ca11b14a9619be"]

Hi Ankur

ignore my previous  replies

updated script

i have tested it with values below but it still eavluates to false, if more than one sys_ids are part of 'approval_secondary'  variable

approval_secondary
2a772fcddb04581818ca11b14a9619b9,ea1d77f9dbf45110b8846c13059619e4

 

 

var curRec = new GlideRecord(advTABLE);
curRec.get(advRECORD); // advTABLE and advRECORD will be the reference to the record passed in from approval workflow

//TODO: add your code below to use the above GlideRecord. For example: 
// answer = curRec.variables.requested_by.manager;
answer = getApprovers(curRec);

function getApprovers(ritm) {

    var roleVar = ritm.variables.approval_secondary.toString();
	
    var roles = 'ea1d77f9dbf45110b8846c13059619e4,f96d773ddbf45110b8846c130596197c';

    roles = roles.split(',');

    var arrayUtil = new global.ArrayUtil();

    var isPresent = arrayUtil.contains(roles,roleVar);


    if (isPresent) {
        // to return a group approver encapsulate the group in a JSON structure with type = group, and id = sys_id of the group as follows:
        var rtnOb = {
            type: 'group',
            id: 'e89395f2db377010b8846c1305961955'
        };
        return rtnOb;

    } else
        return '';

}