How to set value to reference field using sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 02:37 AM
Hi all,
I am having sys_id of company name and i want to set that company name to reference field using sys_id.So how to do it?Please anyone can tell?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 04:21 AM
And how would that work if i am writing a server side JavaScript? Say i have a sys_id and would like to fill a reference field with that reference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 06:02 AM
Hi Wolfgang,
You just need to assign the sys_id to the reference field.
for instance...
gr.assigned_to = 'ec0e5f5b4f10d60026afb1828110c754';
If you're not running on an onBefore type of script, then make sure you also do an update after the assignment.
gr.update();
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 06:13 AM
Well I am within a scripted REST routine and i did exactly that but I end up with an empty reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 06:22 AM
Hi Wolfgang, would you like to share your code to take a look to it?
A couple of pointers that may be helpful:
a) make sure your script does not have errors
b) be aware of what's the display value of your reference. If it's blank/null then the reference field will appear in blank but it will have an information icon next to the field that will take you to the assigned record
c) in case you're not doing it already, you may want to hardcode a given sys_id which you know is a valid one for your reference field. Make sure that one it's one which display values exist.
I hope this helps.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 07:03 AM
Basically its following code:
// open CIs affected table
var cis_aff = new GlideRecord("task_ci");
cis_aff.initialize();
cis_aff.setValue('ci_item', mapping.getValue('sn_configuration_item'));
cis_aff.task = srv.sys_id; // this contains a reference to the incident
cis_aff.xml = 'test test';
cis_aff.update();