Field map script to update a field in another table

clyon
Tera Guru

I have a data source/transform map from the import table to a newly created table. I have the need to update a field in another table from this transform map.

It's not doing anything and I have tried just 1 specific source.u_name and that didn't work either. What am i missing?

u_on_active_directory = field on a different table that needs to be updated from transform .  

u_ad_computer = newly created table that the transform load into from import table.                                                              

Error : Invalid map target u_on_active_directory does not exist in table u_ad_computer = I got working by adding the 'On Active Directory' field to the u_ad_computer table as well. But now it doesn't seem to be doing anything.

Field map:

find_real_file.png

Script:

answer = (function transformEntry(source) {

// Add your code here

//Query Hardware table   if fount set 'on Active Directory = true

var gr = new GlideRecord("alm_hardware");

gr.addQuery('ci.name', source.u_name);

gr.query();

var rec_count = gr.getRowCount();

//if (rec_count >= 1) {

if (gr.next()) {

return "true"; // return the value to be put into the target field

//answer = "true";

}

})(source);

1 ACCEPTED SOLUTION

Not sure, its should work, I tried in this way and it worked for me. Let's see if this helps.



gs.log('u_on_active_directory     :'+ source.u_on_active_directory);


gs.log('u_name     :'+ source.u_name);


var gr = new GlideRecord("alm_hardware");


gr.addQuery('ci.name', source.u_name);


gr.query();


gs.log('count' + gr.getRowCount());


if(gr.next()){


gr.u_on_active_directory = source.u_on_active_directory;


gr.update();


}


View solution in original post

5 REPLIES 5

Great. Please mark the answer correct.