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

Shishir Srivast
Mega Sage

is u_on_active_directory a boolean field? if yes, can you please try just returning true without quotes.



if (gr.next()) {


return true;


}


Yes, it is a Boolean. I made the change you mentioned below.


At that point the 'On Active Directory' field on u_ad_computer WAS updated! But the table/field in field map alm_hardware.u_on_active_directory' is still not being updated.


What am I missing in my script to ensure the target table/field is updated?



Thanks







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();


}


clyon
Tera Guru

Got it working...   the Source_u_on_active_directory is not set until the end of this script, so I changed


gr.u_on_active_directory = source.u_on_active_directory;   to


gr.u_on_active_directory = true;



This sets both fields on both tables !! Thanks for the assistance.