- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi, I have some issues with a transform map I have created. The transform is being used to update existing records in a table with new data.
1. It lets me update fields with invalid values, eg if a field has a choice list, the transform will add my invalid data value to the choice list and input it to the field. I need there to be some sort of validation checks so that if the data value is NOT a valid choice for that field, it aborts the transform.
2. Where a record does not exist in the table, the transform is creating a new record. I want it to check if there is an existing record, if there is then continue with the update. If the record doesnt exist it should NOT create one.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
1. For choice field, when you do the mapping in transform map select ignore so that it will not create a new choice in sys_choice field
2. Create a onBefore transform script and use condition to check if operation is insert, ignore it
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
if (action == "insert")
ignore = true;
})(source, map, log, target);
I hope you appreciate the efforts to provide you with detailed information. If my response helped to guide you or answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
My thoughts
1) for the field map where you are mapping choice field set Choice Action = Ignore, what it does is if incoming choice doesn't match the target choices it doesn't override and create a new choice on target field
Choice action field for Field Map record in Transform Maps
2) for your 2nd requirement you can use onBefore transform script and avoid insertion
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
if (action == "insert")
ignore = true;
})(source, map, log, target);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Refer below, I’m sure it will help.
1- to validate the choices you can use- Choice Action to "Reject" and field level source script as below:
// Sample Field Map Source Script
answer = (function transformEntry(source) {
var sourceValue = source.getValue('your_source_field');
var validChoices = ["choice1", "choice2", "choice3"]; // Your valid choices
if (validChoices.indexOf(sourceValue.toLowerCase()) != -1) {
return sourceValue;
} else {
return '';
}
})(source);
2- and you have to prevent a new record cration so , Use onBefore Transform Script with action validation:
// Sample onBefore Transform Script
(function runTransformScript(source, map, log, target) {
if (action == 'insert') {
ignore = true; // Skip new record creation
}
})(source, map, log, target);
Pro Tip: Always set choice action to "ignore" for reference and choice columns unless necessary to prevent foreign records from being created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
I believe by mistake you marked my other response as correct.
the below response is correct and needs to be marked as correct.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Kiran_25 ,
Did you go through the solution i provided?
If yes please do mark it as helpful and accept as solution
Thanks,
Abin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Refer below, I’m sure it will help.
1- to validate the choices you can use- Choice Action to "Reject" and field level source script as below:
// Sample Field Map Source Script
answer = (function transformEntry(source) {
var sourceValue = source.getValue('your_source_field');
var validChoices = ["choice1", "choice2", "choice3"]; // Your valid choices
if (validChoices.indexOf(sourceValue.toLowerCase()) != -1) {
return sourceValue;
} else {
return '';
}
})(source);
2- and you have to prevent a new record cration so , Use onBefore Transform Script with action validation:
// Sample onBefore Transform Script
(function runTransformScript(source, map, log, target) {
if (action == 'insert') {
ignore = true; // Skip new record creation
}
})(source, map, log, target);
Pro Tip: Always set choice action to "ignore" for reference and choice columns unless necessary to prevent foreign records from being created.