The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How can I update a field on transform only if it is blank?

shembop
Tera Contributor

I have user information which is being pulled in from our HR system. Everything is working fine, but they want to be able to update their information in ServiceNow independent of HR data. So, for instance, if you want to change your email address, phone or mobile number, you can do so, and the daily HR input will leave it alone. The proposed way of doing this is to have a script in the transform that says if employee.phone == "" then the source data is populated into the record. If there is anything in the field - leave it alone.

1 ACCEPTED SOLUTION

Jamsta1912
Tera Guru

Hi Shembop,


Create a field map with employee.phone as the target field. On the field map form, tick the checkbox 'Use Source Script' and then enter a source script like this:



if (target.phone == ''){


        answer = source.u_phone;


}



This assumes 'phone' is the name of the field in your source file.



Jamie.


View solution in original post

7 REPLIES 7

Hi Shembop,


It sounds like the reference to the field in your source is not being recognised. Have you replaced 'u_phone' with the name of your field?


If you are loading from an excel spreadsheet , the name of the field will be 'u_' and then the name as you see it, but in lowercase letters and with spaces replaced by underscores. So for instance, if the column header is 'Phone Number', the field name will be 'u_phone_number', so you would replace the second line of the code with:


answer = source.u_phone_number;


Well, Well, it looks like you are correct, and my data dude changed the header on me. So it looks like this is now working! Thank you so much.


Ajai S Nair
Giga Guru

Hi Shembop,



You can try using a onStart or onBefore script in Transform Scripts as shown below



Transform Map Scripts - ServiceNow Wiki