Transform Map Handling Empty Values for Reference field

kailashthiyagar
Kilo Guru

I have written a script to transform the value from my source(SQL DB) to the Users table in service now. The source column will have Employee ID and it is mapped to Service now Users table using script. It works fine but if the source column is having NULL or empty value, instead of ignoring that one, it updates the matching User record(with empty employee number, the dummy record in Dev) from the Users table.

 

Here is the transform script which i have written..  and i have chosen the choice action as "Ignore".. 

 

In my Users table(Dev env), i have some records created with empty employee numbers, its referecing that if the source column is empty or having null value

 

var ans='';
var userRec=new GlideRecord('sys_user');
userRec.addQuery('user_name',source.u_software_owner);
userRec.query();
while(userRec.next()){
ans =userRec.sys_id;
}

return ans;
1 ACCEPTED SOLUTION

Hi Kailash,

Also I think you need to update your script having only if statement and not while since there should be only 1 user in user table with single user_name field.

var ans='';
var userRec=new GlideRecord('sys_user');
userRec.addQuery('user_name',source.u_software_owner);
userRec.query();
if(userRec.next()){
ans =userRec.sys_id;
return ans;
}

return -1;

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kailash,

Update following script and it should work i.e. it won't update/override the field with empty value

var ans='';
var userRec=new GlideRecord('sys_user');
userRec.addQuery('user_name',source.u_software_owner);
userRec.query();
while(userRec.next()){
ans =userRec.sys_id;
return ans;
}

return -1;

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks https://community.servicenow.com/community?id=community_user_profile&user=19525629dbd81fc09c9ffb651f961989

 

will try and update you.

Hi Kailash,

Also I think you need to update your script having only if statement and not while since there should be only 1 user in user table with single user_name field.

var ans='';
var userRec=new GlideRecord('sys_user');
userRec.addQuery('user_name',source.u_software_owner);
userRec.query();
if(userRec.next()){
ans =userRec.sys_id;
return ans;
}

return -1;

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

what does return -1 does?