Append field in a transform

KB15
Giga Guru

Can I append a target field in a transform? I have files being imported to a table and it can affect the same field multiple times.

I was trying: "target.field = target.field + source.field" but that doesn't seem to work.

1 ACCEPTED SOLUTION

Hey Kkim,



I also tried to do the way you were trying to achieve and i was able to get the value in logs but was not able to append in table.



I believe it will not work in this way. In transform map source field you need to do GlideRecord, I tried to send incident short_description and it worked in this way. Please glide the record based upon you coalesce field.


find_real_file.png


find_real_file.png



Please find the sample code below:



answer = (function transformEntry(source) {


// Add your code here


var gr = new GlideRecord('incident');


gr.addQuery('incident', source.u_number); // pass the source coalesce field


gr.query();


if(gr.next())


{


var val = gr.short_description + ' ' + source.u_short_description;


return val; // return the value to be put into the target field


}


})(source);



Hope this helps.


View solution in original post

5 REPLIES 5

Shishir Srivast
Mega Sage

Can you please try in this way, see if this helps.



var target_val = target.getValue('field_name');


target_val   +=   source.field;


target.field = target_val;


I played with it using an onAfter script instead of the direct field map but no luck. I get a null value for the first portion:



var targetValue = target.getValue('u_field');


targetValue += source.u_field;


target.u_field = targetValue;


target.update();



Result: null123456


Hey Kkim,



I also tried to do the way you were trying to achieve and i was able to get the value in logs but was not able to append in table.



I believe it will not work in this way. In transform map source field you need to do GlideRecord, I tried to send incident short_description and it worked in this way. Please glide the record based upon you coalesce field.


find_real_file.png


find_real_file.png



Please find the sample code below:



answer = (function transformEntry(source) {


// Add your code here


var gr = new GlideRecord('incident');


gr.addQuery('incident', source.u_number); // pass the source coalesce field


gr.query();


if(gr.next())


{


var val = gr.short_description + ' ' + source.u_short_description;


return val; // return the value to be put into the target field


}


})(source);



Hope this helps.


Thanks. That did the trick.