Setting a refernce field to blank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2015 07:44 AM
I am importing an excel field to fill the direct supervisor field and the manger field. However sometimes the Direct supervisor and manger are blank. And I want them to show up as null in serviceNow. The below script does this to the direct supervisor field. How would I now do this to the manger field in the same script?
/**
* For variables go to: http://wiki.service-now.com/index.php?title=Import_Sets_portal
**/
var imp = new GlideRecord('u__apl__persons');
imp.addQuery('sys_import_set', source.sys_import_set);
imp.query();
while (imp.next()) {
// get the users
var u = new GlideRecord('sys_user');
var clearvalue = '' ; //set to undefined. Do not assign a value to the variable.
u.get('employee_number', imp.u_userid);
var super_id = imp.u_manager;
var super_id2 = imp.u_supervisor;
var mgr = new GlideRecord('sys_user');
if (mgr.get('employee_number', super_id)) {
u.manager = mgr.sys_id;
u.update();
}
// Check for blank import value
if (super_id2 == ''){
u.u_direct_supervisor = clearvalue;
}
if (super_id == '')
else if (mgr.get('employee_number', super_id2)) {
u.u_direct_supervisor = mgr.sys_id;
}
}
else if (mgr.get('employee_number', super_id1)) {
u.u_direct_supervisor = mgr.sys_id;
}
u.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2015 08:56 AM
Hi,
Can you try this: u.manager= "NULL";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2015 10:02 AM
Hi John,
Since this is a service side script, you should be able to clear a Reference field by setting it to an empty string. Example:
u.u_direct_supervisor = '';
The clearvalue method you used above works on Clients scripts I believe. This is because the clearvalue variable does not exist, or in javascript terms, it holds the value Undefined. Im not sure that Undefined clears the value on Server side. Personally, I have not tested it. I hope this helps.
Kind regards,
Travis