Help with transform map scripting!

MarleyB
Tera Contributor

Hi!

 

Would like to ask some help regarding transform map scripting, this is to copy a new data uploaded from source field and target field which is located in another table. 

 

Tried BR and unable to make it work, did some research and found about transform map scripting and I'm still trying to learn it.

 

Thanks!

1 ACCEPTED SOLUTION

@MarleyB 

try this

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

	/* 1. Get the value of source field */
	var sourceValue1 = target.name;

	/* 2. Glide record on Table in which you want to update the record */
	var gr = new GlideRecord('service_offering');
	gr.initialize();
	gr.name = sourceValue1 + new GlideDateTime().getLocalDate();
	gr.insert();

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@MarleyB 

transform script is used when you want to handle data manipulation in target field or in some related table being referred by target field

what did you start with and where are you stuck?

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

Hi @Ankur Bawiskar 

 

This is my BRBR.png

@MarleyB 

please share transform map is on which table?

which target field are you referring here and to which table it refers?

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

Hi Ankur, 

 

Transform map is on cmdb_ci_service and target field is on service_offering.

The field from cmdb_ci_service to query is "name" and target field in service_offering is also "name" field, If new item is uploaded in cmdb_ci_service, it should copy the item to service_offering.

@MarleyB 

try this

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

	/* 1. Get the value of source field */
	var sourceValue1 = target.name;

	/* 2. Glide record on Table in which you want to update the record */
	var gr = new GlideRecord('service_offering');
	gr.initialize();
	gr.name = sourceValue1 + new GlideDateTime().getLocalDate();
	gr.insert();

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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