How i use START WITH condition in business rule script

dalvi195
Kilo Contributor

How i use START WITH condition in business rule script

I have idea how to use contains but i am looking for how to use "Start with"

i am working with business rule ( i want to check if caller is from group where group name start with SERVICEDESK so assignment group show that group)

var relationuser= new GlideRecord('sys_user_grmember');

relationuser.addQuery('user',current.caller_id.toString()); //checking user from sys_user_grmember with caller

relationuser.addQuery('group','STARTSWITH','servicedesk');

relationuser.query();

while(relationuser.next())

{

var gname=relationuser.group.getDisplayValue(); //convert sys_id to readable text

if(gname.search('ServiceDesk') > -1 || gname.search('Service Desk') > -1) //contain group name contain service desk  

{

current.assignment_group=relationuser.group;

current.u_servicedesk_relevant=true;

current.u_first_call_resolution=true;

}

}

3 REPLIES 3

Mihir Mohanta
Kilo Sage

Try like below encoded query string


nameSTARTSWITHabs



I place of name use element name of the field and and in place of abs use your starting search text.


Sharique Azim
Mega Sage

In the condition macro, you can use the filter "the field" ,start with   ,<type the string>. all provided the field is string..



in the advanced script , using gliderecord query you can use something similar to gr.addQuery('field','STARTSWITH', '<string>');



refer Using GlideRecord to Query Tables - ServiceNow Wiki


vinothkumar
Tera Guru

Hi Pradeep,



If my understanding is correct, group will be a reference field in sys_user_grmember table, so you have to check the condition similar as group.name instead of group.



var relationuser= new GlideRecord('sys_user_grmember');


relationuser.addQuery('user',current.caller_id.toString()); //checking user from sys_user_grmember with caller


relationuser.addQuery('group','STARTSWITH','servicedesk');



relationuser.query();


while(relationuser.next())


{


var gname=relationuser.group.getDisplayValue(); //convert sys_id to readable text


if(gname.search('ServiceDesk') > -1 || gname.search('Service Desk') > -1) //contain group name contain service desk


{


current.assignment_group=relationuser.group;


current.u_servicedesk_relevant=true;


current.u_first_call_resolution=true;


}



}