Transform Map onBefore script

Priyanka1997
Tera Contributor

Hi All,

 

I have one catalog Item which takes as input an excel template with following columns

Priyanka1997_0-1673342868559.png

I have to Create the entry on cmdb_rel_ci table (CI Relationship) between the parent CI identified by the Parent SNow ID value with the child CI identified by the Child SNow ID value.

 

For this I use 1 BR to copy attachment from RITM to Data Source & then I used Transform Map simply mapping field as follows

Priyanka1997_1-1673343169027.png

Now it working fine only for, If I give input as Parent & Child CI Name but My Requirement Is : I want to insert excel sheet records in target table(cmdb_rel_ci) based on Parent SNow ID value & Child SNow ID value instead of Name of Parent & Child CI.

 

I thought I need to write Transform Map onBefore script.

 

Any help will be appreciated.

 

1 ACCEPTED SOLUTION

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

You don't need an onBefore script, just simply a scripted mapping. Not sure which field on the cmdb_ci table do the parent and child IDs refer to in your Excel, for the sake of an example, let's say asset_tag; then your source script would look something like this for the parent field:

var sourceField = 'u_parent_snow_id'; // change this for child field
var fieldToSearch = 'asset_tag'; // change this to the field that has your IDs
var ciGr = new GlideRecord('cmdb_ci');
ciGr.get(fieldToSearch,source.getValue(sourceField));
return ciGr.getUniqueValue();

View solution in original post

5 REPLIES 5

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

You don't need an onBefore script, just simply a scripted mapping. Not sure which field on the cmdb_ci table do the parent and child IDs refer to in your Excel, for the sake of an example, let's say asset_tag; then your source script would look something like this for the parent field:

var sourceField = 'u_parent_snow_id'; // change this for child field
var fieldToSearch = 'asset_tag'; // change this to the field that has your IDs
var ciGr = new GlideRecord('cmdb_ci');
ciGr.get(fieldToSearch,source.getValue(sourceField));
return ciGr.getUniqueValue();

Hi @Laszlo Balla ,

Thanks for your reply!

 

Parent SNow ID value & Child SNow ID value not present in cmdb_ci table, It is present in Child table of cmdb_ci

 

kindly assist.

Should be the same, just replace 'cmdb_ci' with the name of your child table, and of course update the fieldToSearch variable as needed. The returned sys_id should still work on the target reference.

Hi @Laszlo Balla ,

 

Thank You for your kind help😊, Its working as expected👍