Help on replacing the values through Business rules

Aswin Chandras1
Tera Contributor

HI All

 I will get an value in the last logged in user field in computer table I need to trim that and need to check the same in user_id in the user table. Example value is: abc@example.com. ABC is the user id value or RF ID in user table.

 

If the value is not present in user_id then I need to check RF ID value in user table. Now my requirement is if the value is not present/unavailable in the user table in both user_id and RF ID I need to clear the value from most frequent logged in user in computer table.

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Aswin Chandras1 

share what script you tried and what's not working?

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

Tanushree Maiti
Mega Patron

Hi @Aswin Chandras1 

 

Try this code snippet from BR. It will work. Update query with correct field name as per your instance.

 

var loggedinUserEmail = current.u_logged_in_user;
var loggedinUserEmailSplit = loggedinUserEmail.split('@');
var loggedinUserEmailSplitb4atDrate = loggedinUserEmailSplit[0] + '@example.com';
var loggedinUserEmailSplitb4atDrate1 = loggedinUserEmailSplit[0] + '@example.'; // sometime co.in is also there, avoid it if you dont have these kind of data

var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('email=' + loggedinUserEmail + '^ORuser_idSTARTSWITH' + loggedinUserEmailSplitb4atDrate + '^ORuser_idSTARTSWITH' + loggedinUserEmailSplitb4atDrate1 + '^ORu_rf_id=' + loggedinUserEmailSplitb4atDrate + '^ORu_rf_id=' + loggedinUserEmailSplitb4atDrate1 );
userGr.orderByDesc('sys_created_on');
userGr.query();

if (userGr.next()) {
current.user = userGr.sys_id.toString();
}

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: