- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2022 04:01 PM
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;
}
Solved! Go to Solution.
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 08:31 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2022 07:12 PM
If the script is running in a field map then your need to return a result, not try to map the value directly. Try something like
var myResult;
if(source.u_company_name == 'ABC' || source.u_company_name == 'DEF'){
myResult = source.u_company_name;
} else {
myResult = 'ABC';
}
return myResult;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2022 07:30 PM
Hi,
you can use onbefore transform script to set the value
If(source.u_company_name == 'ABC' || source.u_company_name == 'DEF'){
ignore =false;
} else {
target.u_company_name = 'ABC'; // are you setting correct choice value?
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 04:55 AM
Hi, Thanks for your reply. I tried on Before script and am giving correct choice value, where the target field is a choice list having the choice list as follows. When no match is found from the import data, need to set the company name to 'ABC' (which is not happening). Please help. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 06:27 AM
Hi,
Did you check the script is getting inside the else part or not?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 07:23 AM
Hi Praveen,
May be source company name coming as an object. Please try to convert that to string first and then match it like the below example.
var companyNanme=source.u_company_name+"";
If(companyNanme == 'ABC' || companyNanme== 'DEF'){
}
Regards,
Nayan