Help retrieving Name from sys_user table

Nasir1
Tera Expert

Hi Guys,

 

I need help with retrieving Name from sys_user table.

The scenario is, I am importing Headset information into servicenow. The way integration work is as soon as someone plugs in their headset ServiceNow picks up their headset information and records it in ServiceNow. User's laptop has a small software deployed via SCCM that picks the information and makes a REST call to ServiceNow Table and if no record is found for the device attached creates a new record.

The problem is the users are imported via Azure and the format of user name is username@domain.com.au but the user name format the software sends to servicenow via REST call is without @domain.com.au. What I want to achieve is pick the user name field from Table jabra_device and look up sys_user table, if sys_user contain username from jabra_device then update assigned to field in Jabra_device table with Name from Sys_user table.

 

The table below is the originating username table with no @domain.com.au

 

Table A

find_real_file.png

The sys_user table below is the one with username@yvw.com.au

 

Table B

find_real_file.png

 

Sorry apologies If I am not able to explain it clearly before, but in the simple terms, I want to find out if username from Table A exists in Table B and if it does grab Name from Table B and update Assigned to in Table A.

 

Thanks in advance.

 

Regards

Nasir

1 ACCEPTED SOLUTION

Hi,

update as this

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord("sys_user");
	gr.addEncodeQuery('user_nameLIKE' + current.user_name); // ensure you use correct field name from jabra table
	gr.query();
	if(gr.next()){
		current.assigned_to = gr.getUniqueValue();
		current.update();
	}
})(current, previous);

Regards
Ankur

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the user_name which your software is sending is without the domain name.

you can use that to query in sys_user against the user_name field and find if user is present or not

what script did you start with?

Regards
Ankur

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

(function executeRule(current, previous /*null when async*/) {
var gr=new GlideRecord("sys_user");
 gr.addEncodeQuery(user_nameLIKEcurrent.user_name); // Not Sure this Querry 
 gr.query();
if(gr.next()){
	current.assigned_to = gr.name;
	gr.update();
}
})(current, previous);

Hi Ankur,

I am not sure about the querry but this is what I got in the business rule.

 

any suggestions @Ankur

 

Hi,

update as this

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord("sys_user");
	gr.addEncodeQuery('user_nameLIKE' + current.user_name); // ensure you use correct field name from jabra table
	gr.query();
	if(gr.next()){
		current.assigned_to = gr.getUniqueValue();
		current.update();
	}
})(current, previous);

Regards
Ankur

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