Need to check the logged in user title exact matches the title which i declared in system property.

shashanksha
Tera Contributor

need to check the logged in user title exact matches the title which i declared in system property.

example;- created a system property with title like "FC Manager,Field Service Technician II,Manager, Field Service,MOT DC Manager,Senior Manager, Field Service,Sr Fabricator,Sr Field Service Technician,Sr Service Technician,Supervisor-Field Service" , suppose logged in user title is "SERVICE TECHNICIAN", it should not satisfy the condition, only satisfy the condition when logged in user title is "Field Service Technician II" or "Sr Service Technician".

 

Please help me out.

1 ACCEPTED SOLUTION

@shashanksha 

then store that in a string variable, use split and it gives you array and then search in that array using indexOf.

But storing in property is recommended, considering in future if any title is added/removed then you need not change the script.

I believe I have provided enough guidance on your question.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@shashanksha 

you can get logged in user's title using this and then search in that array

var titleArray = gs.getProperty('propertyName').toString().split(',');
var loggedInUserTitle = gs.getUser().getTitle();

if(titleArray.indexOf(loggedInUserTitle) > -1){
	// logged in user title is belonging to array
}
else{
	// title not present
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello @Ankur Bawiskar ,

 

It is not matching the exact name, suppose looged user title is "Field Service Technician" the system property has "Field Service Technician II" and "Sr Field Service Technician" so it is also going to yes condition but it should go to no.  

@shashanksha 

it won't go inside that IF unless it finds.

then ensure system property holds the correct titles

share your complete script and testing results

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello @Ankur Bawiskar ,

 

system property :- FC Manager,Field Service Technician II,Manager, Field Service,Field Service,Sr Fabricator,Sr Field Service Technician,Sr Service Technician,Supervisor-Field Service

-----------------------

var titleArray = gs.getProperty('jobTitles');

gs.print("property title " + titleArray);

var loggedInUserTitle = gs.getUser().getTitle();

gs.print(" title " + loggedInUserTitle);

if(titleArray.indexOf(loggedInUserTitle) > -1){
    // logged in user title is belonging to array
    gs.print("yes");

}
else{
    gs.print("no");

    // title not present
}  
Please try in your PDI