Update field only on insert and not on update in transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 10:27 AM
Hi,
I was thinking to write a before transform script, so that the transform map runs on a field only on insert and not on update.
We have a field called 'information' and i want to update the field to 'aar integration' only on insert and leave as is on update.
Am i thinking the right approach? Or do i need to put this script in the field mapping itself?
Any ideas here..?
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(action == "insert"){
source.u_information = target.u_information;
}
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 10:32 AM
Hi,
That's correct. Either in an onBefore or in the run script for the transform itself.
Both of those run before the field mapping kick off but after it's determined if it'll be an insert or update.
You could also do it in a field mapping through script, but it's unnecessary.
Up to you (and how the other transform maps have been utilized) as you basically have a few choices 🙂
Only other thing is target.field_name = source.field_name.
You have it backwards in your example.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 02:10 PM
Hi,
Thanks for marking my above reply as Helpful.
If it also helped guide you Correctly, please also mark as Correct.
Thanks and take care! 🙂
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 01:28 PM
Hi Allen,
I have this actual scenario where we need to update the target table field value only if it is an insert.
existing code:// where it updates the field with 'external' both on insert/update
answer = (function transformEntry(source) {
return "External";
}
})(source);
On update action, and the target field has already a value manually filled in, we just want to leave the value as is. I just wrote the below code but it returns 'undefined' when there is an update action on the target field.
Modified code:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 01:41 PM
Hi,
I'd recommend placing this within the script for the transform map itself (so not a field map script or an onBefore/onAfter script etc).
Then use the script as we've previously discussed where
if (action == 'insert') {
target.field_name = "External"; //or target.field_name = source.field_name
}
if on action == insert, it does 'x' then use target.field_name = "External";
Otherwise, it won't do anything else and won't mess with the field, etc.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!