- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 02:08 AM
Hi, I am looking for a script which inserts or updates the row in a specific table. the update criteria is combination of few column values. if this combination don't have the existing unique value in that specific table, insert the row. This script has to run 'OnAfter' on a particular transform map. any leads on this is appreciated. thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 02:16 AM
yes
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var a = source.u_A;
var b = source.u_B;
var c = a + ' ' + b;
var gr = new GlideRecord('table_in_which_you_to_compare');
gr.addQuery('field_name',c);
gr.query();
if(gr.next())
{
log.info('Record already exist no need for creation');
}
else{
target.field_name = c;
target.update();
}
})(source, map, log, target);
I hope this examples gives you some reference to workout your script
Mark my ANSWER as CORRECT and HELPFUL if it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 02:16 AM
yes
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var a = source.u_A;
var b = source.u_B;
var c = a + ' ' + b;
var gr = new GlideRecord('table_in_which_you_to_compare');
gr.addQuery('field_name',c);
gr.query();
if(gr.next())
{
log.info('Record already exist no need for creation');
}
else{
target.field_name = c;
target.update();
}
})(source, map, log, target);
I hope this examples gives you some reference to workout your script
Mark my ANSWER as CORRECT and HELPFUL if it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 02:26 AM
Hi, thanks for the quick reply. May be, I need to specify few more details.
I have a staging table 'A' from which target table 'B' is populated using a transform map. once this is done, the 'OnAfter' Script should load the same data to Table 'C' with the mentioned update logic.
will this script work in that case? how do I specify the target table 'C' in this script?
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 06:45 AM
You populate field values of target not the table.
So, lets say you have value that is coming from Staging table A (that will be source.field_name)
Now based on that value you are searching something in table B ( that will be glide record table)
and once you find or not find data you will be updating value in target table C (that will be target.fieldname)
So this script is apt I believe
Staging Table : Source Table
FInal table in which you want to put data : target table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 06:48 AM
If you are still not clear watch this video I hope you wll get clarity LINK
Mark my ANSWER as CORRECT and HELPFUL if it helps