Script To Insert or Update Record

Monish2
Tera Contributor

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!

1 ACCEPTED SOLUTION

Ct111
Giga Sage

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

View solution in original post

6 REPLIES 6

Monish2
Tera Contributor

HI,

 

the above script works well with the non-referenced fields. however, I found that some fields in my case are referenced and I have the display names but not the sys_ids. what changes we need in that case? thanks!

Use getDisplayName() to verify if record exist or not..