how to update multiple records in target table from one record in source table in a transform map?

ashwanikumar
Tera Expert

Hi All,

i have multiple records in a target table with the same user ID. As per the requirement i want to update all the records in target table using one source record.

i am using an excel with data for 5 fields. rest of the column data will remain same.

how can i achieve this?


Thanks,

KUMAR

12 REPLIES 12

Hello,

 

I make it work today but writing an 'onAfter' script in 'Transform Map'. I am providing a sample script as below - 

Scenario - adding comments aginst the user based on each department who are eligible for promotion.

Code

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var gr = new GlideRecord('sys_user');
var dep = source.u_user_department;
gr.addQuery('department', dep);
gr.setValue('comments', 'eligible for promotion');
gr.updateMultiple();

})(source, map, log, target);

 

Please mark it 'helpful' if it really helps you.......thanks.

Chandan1
Tera Contributor

You can use below script in transform map to update multiple records of the target table for one source record.

answer = (function transformEntry(source) {

// Add your code here
//return ""; // return the value to be put into the target field

var gr = new GlideRecord('sys_user');
var goc = source.u_goc;
gr.addQuery('u_goc_code',goc);
gr.addQuery('active',true);
gr.addQuery('sys_class_name','sys_user');
gr.setValue('u_lvid', source.u_lvid);
gr.updateMultiple();

})(source);

Hello Chandan,

can you please specify where to use it specifically?

Is this can be used as a script on the main transform map or can be used as a 'onBefore' or 'onAfter' script?

nandhinirengara
Tera Contributor

Was this successful for anyone? I am trying to implement the exact same thing. 

I want to update multiple records in the target table ( the records are already existing) with one source record.

 

I believe it is possible but how ?

 

Hello,

 

I make it work today but writing an 'onAfter' script in 'Transform Map'. I am providing a sample script as below - 

Scenario - adding comments aginst the user based on each department who are eligible for promotion.

Code

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var gr = new GlideRecord('sys_user');
var dep = source.u_user_department;
gr.addQuery('department', dep);
gr.setValue('comments', 'eligible for promotion');
gr.updateMultiple();

})(source, map, log, target);

 

Please mark it 'helpful' if it really helps you.......thanks.