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

Hi Laszlo,

I want to insert/update CI which are taken as an excel in an ritm. I've already created an Data source, Scheduled Import, Business rule to copy the attachment from RITM to Data Source & then trigger the schedule the import set. Now I want to differentiate between two Transform scripts for each type of CI(two different class CIs), how to do that?