Issue with populating Assigned To field on Incident form

Suggy
Giga Sage

Need to set Assigned To field in Incident form via REST API/Business rule.

 

If I use below script,

rec.assigned_to = 'Andrew Och'; // THIS WORKS

 

but if I use below script,

rec.setValue('assigned_to', 'Andrew Och');// DOES NOT work. Why?

 

Infact everyone says use sys_id for reference fields. Then why 1st script worked? Why 2nd script failed?

 

PS - For User table, Diplay is set to FALSE for ALL the fields. 

Also in Assigned To dictionary attribute, its all EMPTY.

 

 

11 REPLIES 11

Tony Chatfield1
Kilo Patron

Hi, this appears to be a duplicate of this post\thread

Issue with setting the REFERENCE field - ServiceNow Community
As per my comments in your other post sys_id's are used to assign reference data, not display values and I would suspect that the assigned_to field is being set elsewhere\by a different script.

Hi Tony, No I am only running that script, using scripts-background

Hi Suggy, testing in a PDI background window I see the same behavior as you do, this appears to be as SNC interprets/matches both value and display name when setting values via dot.walk but setValue() only accepts the objects 'value'.
I have never previously dot.walked to display values and would personally avoid this approach unless you can be 100% sure that the display values in your reference data are unique.

 

var rec = new GlideRecord('incident');
rec.get('979b6060a5954300964fa3aa92874155');

//rec.assigned_to = '5137153cc611227c000bbd1bd8cd2007'; // David Loo
//rec.assigned_to = '46d44a23a9fe19810012d100cca80666'; // Beth Anglin
//rec.assigned_to = 'David Loo';
//rec.assigned_to = 'Beth Anglin';

//rec.setValue('assigned_to', 'Beth Anglin');
//rec.setValue('assigned_to', 'David Loo');
//rec.setValue('assigned_to', '5137153cc611227c000bbd1bd8cd2007'); // David Loo
//rec.setValue('assigned_to', '46d44a23a9fe19810012d100cca80666'); // Beth Anglin

rec.setWorkflow(false);
rec.update();

 

Hi Tony, I have not dot.walked anywhere 🙂