testing inbound email action query

servicenow lath
Tera Contributor

I need this inbound email action to be run only for ITIL users.

 

what changes do i need to do in this script?

 

 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @servicenow lath ,

try below code.

var mail=email.origemail;
var usr=new GlideRecord('sys_user');
usr.addQuery('email',mail);
usr.query();
if(usr.next()){
var sysid=usr.sys_id;
var usrRole=new GlideRecord('sys_user_has_role');
usrRole.addQuery('user',sysid);
usrRole.addQuery('role','give ITIL role sysid');
usrRole.query();
if(!usrRole.next()){
//add your inboud action script it will work for role other than ITIL
}

}

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

10 REPLIES 10

Pavankumar_1
Mega Patron

Hi @servicenow lath ,

you can add below line

if (gs.hasRole("itil")) {
//provide the script with in the if condition
}
If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

@Pavankumar_1 tried it is not WOrking.

Hi @servicenow lath ,

Server side gs.hasRole() it is the only method to function based on logged in user role or When to Run tab on inbound action use 

where you are trying this inbound action?

If it is client instance add logs and see the results

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

yeah i haveChanged @Pavankumar_1 

But how to test it in dev instance?