Setting a refernce field to blank

johnpettit
Kilo Explorer

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();
}  

2 REPLIES 2

ghaing
Giga Expert

Hi,


Can you try this:     u.manager= "NULL";


tltoulson
Kilo Sage

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