Transform map script

shivaadapa
Tera Expert

Hi

I don't understand this one "Any GlideRecord's insert calls should be written in "after" transform map script as inserting into reference/target tables" please provide me any example?

2 REPLIES 2

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @shivaadapa ,

Please check out this link

https://docs.servicenow.com/bundle/tokyo-platform-administration/page/script/server-scripting/refere...

 

Thank you

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Anand Kumar P
Giga Patron
Giga Patron

Hi @shivaadapa ,

var cluster = source.u_cluster;
var cgr = new GlideRecord('cmdb_ci_cluster');
cgr.addQuery('name', cluster);
cgr.query();
while (cgr.next()) {
    var rgr = new GlideRecord('cmdb_rel_ci');
    rgr.initialize();
    rgr.parent = cgr.sys_id; 
 rgr.child.setDisplayValue(source.u_name);
rgr.type.setDisplayValue("Hosted on::Hosts");
    rgr.insert();
}

The script goes through each cluster record, and for each cluster, it creates a relationship record that indicates the source CI is hosted on that cluster. The relationship is established using the 'Hosted on::Hosts' type.

It perform additional processing or customization after a record has been transformed and inserted into the target table.
The "onafter" script allows you to perform actions that depend on the record being present in the target table.
In this case, it checks if there's a related task and updates it. This is something you typically do after the record has been inserted.


Mark it helpful and solution proposed if it serves your purpose.

Thanks,

Anand