Help on replacing the values through Business rules

Aswin Chandras1
Tera Contributor

Hi All,

 

I have a field called logged in user in computer table which is updated through discovery as an email id not as an user id.

 

We are copying the email id and trimming the same user id within servicenow and comparing with sys_user table and copying the value in the field called frequent user.

 

Now the ask is if the logged in user gets updated in the field I need to update in the frequent user field through business rule. How to achieve this.

 

I need to trim and get only the user id. The example value in logged in user would be 12345@example.com. In this 12345 is the user id available in the user table.

 

10 REPLIES 10

Tanushree Maiti
Tera Patron

Hi @Aswin Chandras1 

 

Use this script (it is for BR)

 

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_nameSTARTSWITH' + loggedinUserEmailSplitb4atDrate +  '^ORuser_nameSTARTSWITH' + loggedinUserEmailSplitb4atDrate1 );
            userGr.orderByDesc('sys_created_on');
            userGr.query();
 
            if (userGr.next()) {
                current.user = userGr.sys_id.toString();
            }
 
 
 
Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti