Transform Map Condition - Update target table

Desmo
Mega Guru

Hello,

I have transform map with an onbefore script to query the target table. The intent is to only update specific records based on a field value. I'm using a coalesce field. Note: There can be more than one record that has the same value in the coalesced field, which is the reason I like to use a query. Also, a record should not be inserted if no match is found.

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

var gr = new GlideRecord('ast_service');
gr.addQuery('type', 'Contract'); //look for this record type
gr.query();
if(!gr.next()){

update = true;

}

else{

if (action == 'insert' ){
 ignore = true;
 }
}

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

 

Thanks.

5 REPLIES 5

Tony Chatfield1
Kilo Patron

Hi, Your requirement is not clear as to whether you are updating the transform target if matched to your glide query or if you are updating the returned glide record? For either solution I normally set a true/false variable at the beginning of my transform scripts and then assign it to ‘ignore’ as the last action in the transform. So something like this.

doNotProcess = false; // default is process record ie ignore = false

if(action = ‘insert’) {
//No insert
doNotProcess = true;
} else {
// must be an update.

var recCheck = new GlideRecord(‘yourTable’);
// query conditions
recCheck.query();

if(recCheck.next()) {
target.field = recCheck.field;

/*Or if updating the glide record.
recCheck.field = source.field
recCheck.update();
doNotProcess = true;

*/

} else {
// no match so ignore
doNotProcess = true;

}

}

ignore = doNotProcess;

Allen Andreas
Administrator
Administrator

Hello,

You're not really telling us what the issue is and honestly, you've posted about transform map and something like this several times previously. So we'd love to see that information used to carry the conversation to a more advanced state.

Your other threads about this are:

https://community.servicenow.com/community?id=community_question&sys_id=e92954eb1ba96c10ed6c9979b04b...

https://community.servicenow.com/community?id=community_question&sys_id=aaff058b1b25a010ed6c9979b04b...

So what do you need help with?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

The dev requirements continue to change.

This information in this post is valid, where the I want to ignore inserting records.
https://community.servicenow.com/community?id=community_question&sys_id=aaff058b1b25a010ed6c9979b04bcb85

The new ask is to query and update a specific record type, i.e. gr.addQuery('type', 'contract').

The script would look for a record type equals contract, match the coalesce field, and then update. Otherwise, ignore. Or, another way to say it is, only update this record type.


Thanks!

Dan20
Tera Contributor

I found this whilst looking for a solution for my issue but for yours. If I understand what you're asking, instead of using an On Before script, could you not just a normal mapping record, chose 'Use source script', choose the target field you want to coalesce on then in the code do

 

if(target.field == 'fieldValue'){

// do something...

}

 

Hope this helps!