transform script target field

Praveen75
Tera Contributor

Hi, I have a scenario where if I get any value that doesn't exist in choice list (target table field is a choice list where label and field = ABC). The issue is how to set the target field value to the default value as 'ABC'. Please help me with this. Thanks.

If(source.u_company_name == 'ABC' || source.u_company_name == 'DEF'){

ignore =false;

} else {

target.u_company_name = 'ABC';  // not able to get this set

ignore =true;

}

1 ACCEPTED SOLUTION

Glad to know that my script worked.

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Nayan Mahato
Tera Guru

Hi Praveen,

 

Instead of writing the above code in the transform map's script, create a field map and use the source script. as per the below example shown in the screenshot, you can see the target field  "IT Profile" is a list type of field and we are setting up the default as "Traditional Worker " when it is not getting any matching value so you can use the same concept in your case. Make sure to choose choice action as ignore otherwise it will create new choice values. Thanks.

find_real_file.png

 

Please mark my answer as helpful if that solves your concern. Thanks in advance!

 

Regards,

Nayan

I have tried this way. But when I load the records, getting the null pointer exception. Not sure why.

Hi Praveen,

Can you show me the screenshot of the script, and the error, please? And make sure to return correct choice values? Thanks.

Regards,

Nayan

Tony Chatfield1
Kilo Patron

Hi, you don't make it clear if this is a field transform or before transform script?

I assume a before transform based on the format and use of 'target' ?
Looking at your code you are setting ignore = true, which will mean that your row insert\update for the record being processed will be ignored., so no record is processed against which the default value will be set.

What happens if you remove ignore = true?

Also ignore = false is implied and is not required, unless you are setting ignore = true earlier in your script?