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

Vishal Birajdar
Giga Sage

Hello @MarleyB 

 

You will find it in related list of transform map.

 

VishalBirajdar_0-1705302941240.png

 

You can user onBefore/onAfter script as per your need to update data in another table.

 

VishalBirajdar_1-1705303218719.png

 

Script :

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

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

    /* 2. Glide record on Table in which you want to update the record */
    var gr = new GlideRecord('table name');
    gr.addQuery('', ''); // your query to update specific record
    gr.query();

    if (gr.next()) {
        gr.field_1 = sourceValue1;
        gr.update();  //update record
    }

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

 

 

Hope this helps...!!!

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi Vishal,

Used your scripts and updated based on the source field and target field but not working. Not sure if line 8 is correct for the query

 

 

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

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

    /* 2. Glide record on Table in which you want to update the record */
    var gr = new GlideRecord('service_offering');
    gr.addQuery('name', ''); // your query to update specific record
    gr.query();

    if (gr.next()) {
        gr.name = sourceValue1;
        gr.update();  //update record
    }

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

Harish Bainsla
Kilo Patron
Kilo Patron

Hi

(function executeTransformMap(source, map, log, target /*undefined onStart*/ ) {
// Check if the source field has a value
if (source.source_field) {
// Copy the value to the target field
target.target_field = source.source_field;
}
})(source, map, log, target);

Hi @Harish Bainsla,

This is to copy value to another table and to copy only new record