- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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 weeks ago - last edited 3 weeks 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 weeks ago
hi @rconstantino ,
you can mark multiple solutions as Accepted. if my solution helps you in resolving your issue, please mark it as Accepted Solution and close the thread.
Thanks,
Deepak Sharma