Finding User record for reference table from User ID

Dan Brown2
Kilo Sage

Hi,

I have a custom table with certain user details on, that I want to use to create an incident for that user - using those details to populate the caller_id field.

 

When I use the name field, then it would work fine:

 
 var inc = new GlideRecord('incident');
        inc.initialize();
        inc.caller_id = current.u_name;

 

But I realise that the name may not be unique on the sys_user table. 

I also have their user_id which would be unique, but changing the script to this, doesn't work.

 inc.caller_id = current.u_user_id;

I am sure I am missing something that I could use to achieve this?

Thank you,

Dan

1 ACCEPTED SOLUTION

Bhuvan
Kilo Patron

@Dan Brown2 

 

Try below,

 

Bhuvan_0-1755527294932.png

Bhuvan_1-1755527406983.png

 

var myName='abel.tuter';
var myUser = new GlideRecord('sys_user');
myUser.addQuery('user_name','=',myName);
myUser.query();
while(myUser.next())
{
inc_name=inc.user_name;
var inc = new GlideRecord('incident');
inc.description='Test Incident using User ID';
inc.short_description='Test Incident using User ID from sys_user record';
inc.caller_id=myName;
inc.impact=3;
inc.urgency=3;
inc.insert();
}

 

If this helped to answer your query, please accept the solution and close the thread.

 

Thanks,

Bhuvan

View solution in original post

1 REPLY 1

Bhuvan
Kilo Patron

@Dan Brown2 

 

Try below,

 

Bhuvan_0-1755527294932.png

Bhuvan_1-1755527406983.png

 

var myName='abel.tuter';
var myUser = new GlideRecord('sys_user');
myUser.addQuery('user_name','=',myName);
myUser.query();
while(myUser.next())
{
inc_name=inc.user_name;
var inc = new GlideRecord('incident');
inc.description='Test Incident using User ID';
inc.short_description='Test Incident using User ID from sys_user record';
inc.caller_id=myName;
inc.impact=3;
inc.urgency=3;
inc.insert();
}

 

If this helped to answer your query, please accept the solution and close the thread.

 

Thanks,

Bhuvan