- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
We have an onAfter script on a Transform Map (see attached) that is updating the Asset Location (cmn_location) to an incorrect location.
Can someone please help me understand this script?
Thank you in advance,
Rachel
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Here is the explanation.
1.Line number 3 checks if there is an asset property in target record
2.Line number 4 create a variable a and initialises it with a Glide record object referring to alm_hardware table
3. Line number 5 fetches the hardware asset record.
4. Line number 7 create a variable l and initialises it with a Glide record object referring to cmn_location table
5 Line number 8 gets the cmn_location record where u_site_number is same as u_room_number property of the source record.
6. Liner number 10 assigns the value of cmn_location sys_id to the location property of variable created in step number 2.
7. Line number updates the glide record variable a.
Also, you can update the code as follows to map the location correctly.
(function runTransformScript(source, map, log, target) {
if (target.asset) {
var a = new GlideRecord('alm_hardware');
if (a.get(target.asset)) {
var l = new GlideRecord('cmn_location');
if (l.get('u_site_number', source.u_site_number)) {
a.location = l.getValue('sys_id');
a.update();
}
}
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
hi @rconstantino
Assuming you want to match the room number to a room field or site number to a site field, update lines 8–11 .
If matches u_site_number on the location record with source.u_room_number from the import file.
(function runTransformScript(source, map, log, target) {
if (target.asset) {
var a = new GlideRecord('alm_hardware');
if (a.get(target.asset)) {
var l = new GlideRecord('cmn_location');
//Match site number to site number or room to room
if (l.get('u_site_number', source.u_site_number)) {
a.location = l.sys_id;
a.update();
} else {
log.warn('Location not found for site number: ' + source.u_site_number);
}
}
}
})(source, map, log, target);
Happy to help! If this resolved your issue, kindly mark it as the correct answer ✅ and Helpful and close the thread 🔒 so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Here is the explanation.
1.Line number 3 checks if there is an asset property in target record
2.Line number 4 create a variable a and initialises it with a Glide record object referring to alm_hardware table
3. Line number 5 fetches the hardware asset record.
4. Line number 7 create a variable l and initialises it with a Glide record object referring to cmn_location table
5 Line number 8 gets the cmn_location record where u_site_number is same as u_room_number property of the source record.
6. Liner number 10 assigns the value of cmn_location sys_id to the location property of variable created in step number 2.
7. Line number updates the glide record variable a.
Also, you can update the code as follows to map the location correctly.
(function runTransformScript(source, map, log, target) {
if (target.asset) {
var a = new GlideRecord('alm_hardware');
if (a.get(target.asset)) {
var l = new GlideRecord('cmn_location');
if (l.get('u_site_number', source.u_site_number)) {
a.location = l.getValue('sys_id');
a.update();
}
}
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Thank you
I updated the script and the location is no longer changing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
This is what your script does.
1. The script takes invokes GlideRecord object of asset record that was transformed.
2. It finds the record in Location table whose Site Number field matches imported field 'Room Number' from data import.
3. The Location record is set as reference in Asset location field and asset record is updated.
You can use the following line in your code to work better:
a.location = l.getUniqueValue();
Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.
Kind Regards,
Ehab Pilloor