- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 10:42 AM
I have a transform map setup with a primary map script and an onBefore script. I can't seem to get the onBefore script to function. Either Does anyone have any suggestions why it might not be working? In general I do not want the transform to create any new CI's and I only want CI's updated where the u_vendor_job_id on the target record is empty. The Vendor Job ID field is just a standard string field. Nothing unique.
Primary map script
if (action == 'insert') {
ignore == true;
}
onBefore script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(target.u_vendor_job_id != '')
ignore = true;
})(source, map, log, target);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 02:54 PM
Here's what I got to work. Given a source file like this:
Name | Rank | SerialNumber |
Billy Bob | MajorDomo | H3422B |
Nestor | Lackey | R344-9 |
Xerxes | Emperor | 35563 |
Lebowski | Dude | 11111 |
And a target table with only the first three rows:
I set up my onBefore script like this. Note that my script, and not a Field Map, is deciding what the coalesce column is.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// No inserts
var gr = new GlideRecord("x_acso_test_app_target_row");
gr.addQuery("u_serial_number", source.u_serialnumber);
gr.query();
if(!gr.next()) {
ignore = true;
return;
}
})(source, map, log, target);
When I run the transform, the target table is unchanged.
To prevent updates unless the target Rank column is empty, I updated the onBefore:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
...
// No update unless target rank is empty
if(target.u_rank != '') {
ignore = true;
return;
}
})(source, map, log, target);
Now if I update my source file with a new value but leave the target table alone, no update is done.
But if I clear out the target column and run the transform again, the update is applied.
It seems to me you should not have to resort to using GlideRecord like this, but this is the only thing I found that worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 02:30 PM
Looks like your onbefore script if statement is missing curly brackets, try the below
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(target.u_vendor_job_id != '') {
ignore = true;
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 02:59 PM
In JavaScript, if the brackets are omitted the remainder of the line is considered the body, or the following line if there is no remainder.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 02:54 PM
Here's what I got to work. Given a source file like this:
Name | Rank | SerialNumber |
Billy Bob | MajorDomo | H3422B |
Nestor | Lackey | R344-9 |
Xerxes | Emperor | 35563 |
Lebowski | Dude | 11111 |
And a target table with only the first three rows:
I set up my onBefore script like this. Note that my script, and not a Field Map, is deciding what the coalesce column is.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// No inserts
var gr = new GlideRecord("x_acso_test_app_target_row");
gr.addQuery("u_serial_number", source.u_serialnumber);
gr.query();
if(!gr.next()) {
ignore = true;
return;
}
})(source, map, log, target);
When I run the transform, the target table is unchanged.
To prevent updates unless the target Rank column is empty, I updated the onBefore:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
...
// No update unless target rank is empty
if(target.u_rank != '') {
ignore = true;
return;
}
})(source, map, log, target);
Now if I update my source file with a new value but leave the target table alone, no update is done.
But if I clear out the target column and run the transform again, the update is applied.
It seems to me you should not have to resort to using GlideRecord like this, but this is the only thing I found that worked.