- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2021 04:42 PM
Hi all,
I have an onAfter transform map that I use to set some static values.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
target.active = 'true';
target.url = 'fsm?id=fm_index#';
target.update();
})(source, map, log, target);
when I run the import, nothing updates. I have tried target.field_name as well as target.setValue, and neither work... is there something I am missing here?
Thanks 🙂
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2021 05:21 PM
Hi,
I don't think you have access to the target to be able to update like that.
What I've always had to do was conduct a GlideRecord query, find the record, which you have access to the elements, such as sys_id, etc. so it's pretty short code and then update the gliderecord object that way.
onAfter is after the row has already been addressed so you're going back through to pull it back up.
var gr = new GlideRecord('table_name');
gr.get(target.sys_id);
gr.setValue('active', true);
gr.setValue('url', 'fsm?id=fm_index#');
gr.update();
I do see that "target" is technically a gliderecord object, but if target.update(); isn't working, and I actually have never tried to use it like that in an onAfter, it leads me to believe that you'd want to "re-glide" and get it again. I'm trying to find specific examples of target.update() being needed and it working, if at all.
Otherwise, in an onBefore transform script, you can just set the values such as you did in your script (and you don't even need target.update() for that either).
Replace 'table_name' with the name of the table and you should be good to go.
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
04-21-2021 05:21 PM
Hi,
I don't think you have access to the target to be able to update like that.
What I've always had to do was conduct a GlideRecord query, find the record, which you have access to the elements, such as sys_id, etc. so it's pretty short code and then update the gliderecord object that way.
onAfter is after the row has already been addressed so you're going back through to pull it back up.
var gr = new GlideRecord('table_name');
gr.get(target.sys_id);
gr.setValue('active', true);
gr.setValue('url', 'fsm?id=fm_index#');
gr.update();
I do see that "target" is technically a gliderecord object, but if target.update(); isn't working, and I actually have never tried to use it like that in an onAfter, it leads me to believe that you'd want to "re-glide" and get it again. I'm trying to find specific examples of target.update() being needed and it working, if at all.
Otherwise, in an onBefore transform script, you can just set the values such as you did in your script (and you don't even need target.update() for that either).
Replace 'table_name' with the name of the table and you should be good to go.
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
04-01-2022 05:50 AM
target is accessible in an onAfter script.
I just used target.update() in an onAfter script in San Diego and it worked fine for me. The Import Set record does not reflect it did an update, but the target record does.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2021 05:31 PM
got it.
Changed it to an onBefore script and dropped the target.update() and all was good.
Another thing to note is my URL was incorrect as well, needed a leading / before the url
target.url = '/fsm?id=fm_index#';