how to compare 2 strings to get the group name

Priya75
Tera Contributor

I want to match 2 strings. eg :- absc-suuportGroup and absc-suuportGroup-Approval group , 

if the string matches from the beginning till group- then i wnat to fetch the sys id of absc-suuportGroup-Approval.

 

 

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@Priya75 Here is the script you can use.

var firstGroup = "absc-suuportGroup";
var secondGroup = "absc-suuportGroup-Approval group";
if(secondGroup.startsWith(firstGroup)){
    gs.info('match'); 
    var glideGroup = new GlideRecord('sys_user_group');
    if(glideGroup.get('name',secondGroup)){
        gs.info(glideGroup.sys_id);
    }   
}
else{
    gs.info('no match');
}

 

Please mark the answer helpful and correct if it manages to address your requirement.

i don't have second group name, i need to glide that from table and match it.

@Priya75 Here is the updated script.

 

 

 

var firstGroup = "absc-suuportGroup";
var glideGroup = new GlideRecord('sys_user_group');
glideGroup.addEncodedQuery('nameSTARTSWITH'+firstGroup);
glideGroup.query();
if(glideGroup.next()){
    gs.info(glideGroup.getValue('sys_id'));
}
else{
gs.info('no match found');
}

 

 

Hi, 

So in this scenario, it matches the first group name string but what i want  to match the first string, but it should end with  -approval also. So it should be "absc-suuportGroup-Approval" , it should match the absc-suuportGroup but end with approval .