How to update values using a transform map in the related list of the target table

shrutim
Kilo Contributor

Hello All,

I have a requirement to create a data source and using transform map , map the following fields with the target table.

Site Id

Site City

Site Country

Company

Region

Now, my concern is that "Site city and Site Company " are not directly in the target table "ABC". but they are present in the related list(company) of this table(ABC). So I am not able to map Site city and Site country with the target table.

So, how can I map source fields with the target table related list fields.

Thanks In advance!

Shruti Malaviya

1 ACCEPTED SOLUTION

Deepa Srivastav
Kilo Sage

Hi Shruti,



All the related lists are the individual tables in Service Now and there is no way of updating the fields information directly from the transform map for the target table.



If you want to use only one transform map, then the transform scripts should be defined to glide into all the related list tables and update the information. We can do it by using some common code ( function call) for update of the information. Add an 'onAfter' script to your map.



The script can insert records into your related table. Simply set the reference field on the related record to the sys_id of the record that's been inserted by the transform map   (target.sys_id).



Here's a very rough example that creates a new record in the Software instance table (cmdb_software_instance):



var sftInst = new GlideRecord('cmdb_software_instance');


sftInst.software = source.softwareName;


sfInst.installed_on = target.sys_id;


sfInst.insert();



The other solution to keep it simple, define multiple transform maps, one for each target table(related list).



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


View solution in original post

5 REPLIES 5

Deepa Srivastav
Kilo Sage

Hi Shruti,



All the related lists are the individual tables in Service Now and there is no way of updating the fields information directly from the transform map for the target table.



If you want to use only one transform map, then the transform scripts should be defined to glide into all the related list tables and update the information. We can do it by using some common code ( function call) for update of the information. Add an 'onAfter' script to your map.



The script can insert records into your related table. Simply set the reference field on the related record to the sys_id of the record that's been inserted by the transform map   (target.sys_id).



Here's a very rough example that creates a new record in the Software instance table (cmdb_software_instance):



var sftInst = new GlideRecord('cmdb_software_instance');


sftInst.software = source.softwareName;


sfInst.installed_on = target.sys_id;


sfInst.insert();



The other solution to keep it simple, define multiple transform maps, one for each target table(related list).



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Hello Deepa,



Thanks for your response ... I wrote a transform script only with slightly different code and it worked.




Regards,


Shruti Malaviya


Thanks for the update Shruti, would you mind marking the answer as correct and thus close the thread


staticCrash
Tera Guru

Based on the Accepted Answer, i was able to solve my issue:

I have to update a field that's in cmdb_ci_computer.  The field is u_control_number.

The transform map inserts/updates the cmdb_ci.  Then the cmdb_ci_computer is auto updated, minus the u_contol_number.  

 

So here is the transform map after script that fixes my issue:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	
	//fill in the cmdbCICompuer's control number field after the inserts/updates occur for cmdb_ci &
	//cmdb_ci_computer.
	var grCCC = new GlideRecord('cmdb_ci_computer');
	if (grCCC.get(target.sys_id)) {
		grCCC.u_control_number = source.u_control_number;
		grCCC.update();
	}
	
	
})(source, map, log, target);

 

Thank you,

 

Jay