- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 02:41 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 03:17 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 03:17 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2024 02:10 PM
"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.