Transform Map Script to update the field values of sub-class / child table

Pradnya6
Giga Contributor

I have created a common transform map for loading configuration items.
Configuration Items that I want to load are cmdb_ci_server & cmdb_ci_msd.

I create a transform map where target table is cmdb_ci.
In Transform map script I added following code

var clstype = source.type.toString(); // this will be cmdb_ci_server / cmdb_ci_msd
target.sys_class_name= clstype;

Also included the field mapping.
This works fine for the column fields of the cmdb_ci table as it is the target table.

Now cmdb_ci_msd has 2 additional fields Test1 & Test2 which are not there in cmdb_ci.
Is there any option to add / update these fields?

One method is by adding script on After with glide record. Can I get some option to add these columns in onbefore script as I observed when it runs the transform map it created 1 entry in target table and another one in the child table for adding relationship.

Please suggest as I want to avoid the extra load by adding onAfter Script.

3 REPLIES 3

Mark Stanger
Giga Sage

Can you post your onAfter script?


Here is the onAfter function



function updateRecords()
{
var deviceClass = target.sys_class_name.toString();
var gRow;
if ('u_cmdb_ci_server' == deviceClass)
{
gRow = getGlideRow(deviceClass, target.sys_id.toString());
if (gRow.next())
{
gRow.u_server_os = source.u_server_os.toString();
gRow.u_os_version = source.u_os_version.toString();
gRow.update();
}
}
else if ('u_cmdb_ci_netgear' == deviceClass)
{
gRow = getGlideRow(deviceClass, target.sys_id.toString());
if (gRow.next())
{
gRow.u_access_no = source.u_access_no.toString();
gRow.u_version = source.u_version.toString();
gRow.update();
}
}
}


Your script looks good. I haven't tried this type of thing before with on onAfter script but I'm guessing that your update is just happening before the original insert happens. In any case, there's not a way to do this onBefore so you'll probably just need to have 2 imports to make it work.