The CreatorCon Call for Content is officially open! Get started here.

Need to write Transform Script for checking record in the table is already there than update it

JohnDF
Mega Sage

Hi Everyone,

 

I need to write a TransformMap Script for checking a record is existing already in the table than update the records with the transform map imported fields. Here is the specific requirement:

 

The transform map script should update alm_hardware records where reference  target field "ci" start with the value provided in source field u_ilv_servername.

 

How I need to write this script and where in the table trasnform map? Thanks for help and advice.

1 ACCEPTED SOLUTION

Weird
Mega Sage

I'm not sure I understand what you're trying to achieve.
Do you want to update a record in alm_hardware only if the CI field starts with the source.u_ilv_servername?

You can change your coalesce field into a script:

var alm = new GlideRecord("alm_hardware");
alm.addQuery("ciSTARTSWITH" + source.u_ilv_servername);
alm.query();
if(alm.next()){
answer = alm.sys_id; //If Match is found, return the sys_id of alm hardware record
}else{
answer = -1;
//Or you can say
//ignore = true;
//if you don't want to create a record
}

Then mark the target field as sys_id. I'm assuming your target table is alm_hardware.

What this does?
Your source script simply checks if a alm_hardware record is found where the CI fields name starts with the value in source.u_ilv_servername. If a match is found the sys_id of the alm_hardware is used as a coalesce for the alm_hardware record.
If no match is now found, it's considered new. You can also use "ignore = true" to now create a new record.

View solution in original post

2 REPLIES 2

Weird
Mega Sage

I'm not sure I understand what you're trying to achieve.
Do you want to update a record in alm_hardware only if the CI field starts with the source.u_ilv_servername?

You can change your coalesce field into a script:

var alm = new GlideRecord("alm_hardware");
alm.addQuery("ciSTARTSWITH" + source.u_ilv_servername);
alm.query();
if(alm.next()){
answer = alm.sys_id; //If Match is found, return the sys_id of alm hardware record
}else{
answer = -1;
//Or you can say
//ignore = true;
//if you don't want to create a record
}

Then mark the target field as sys_id. I'm assuming your target table is alm_hardware.

What this does?
Your source script simply checks if a alm_hardware record is found where the CI fields name starts with the value in source.u_ilv_servername. If a match is found the sys_id of the alm_hardware is used as a coalesce for the alm_hardware record.
If no match is now found, it's considered new. You can also use "ignore = true" to now create a new record.

"You can also use "ignore = true" to not create a new record."

 

Will this still update the record with other information in the record? 

 

In my case, a record already exist with an email address field being coalesce.  I can't create a new record with that email address, so I just want to update the existing.