Help to script a set value in a transform map

Cirrus
Kilo Sage

Does anyone have a similar script for this or can advise how to achieve please.

We have a transform map on cmdb_model to create product models. One of the fields is the reference field to Manufacturer, and the Choice Action is set to create, so if the Manufacturer on the source information import is not referenced in core_company table, the transform will create a new entry.

The problem is that on core_company table there are three checkboxes for Customer, Manufacturer and Vendor, and so when a new company is created, we need to be able to set the Manufacturer checkbox to true (otherwise necessary business rules we have are automatically creating the new manufacturer in the class of account).

Question is how to set this on the new record created by the transform, when the transform is on cmdb_model.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onAfter transform script for this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	var rec = new GlideRecord('core_company');
	rec.get(target.company); // give here the field which refers to company table
	rec.manufacturer = true;
	rec.update();

})(source, map, log, target);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onAfter transform script for this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	var rec = new GlideRecord('core_company');
	rec.get(target.company); // give here the field which refers to company table
	rec.manufacturer = true;
	rec.update();

})(source, map, log, target);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Legend as ever, thanks Ankur

@Cirrus 

Glad to help.

Please mark response helpful as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader