Copy a tranform map using script

kiki330611
Kilo Expert

Hello Everyone,

I am looking for a piece of code that would allow me to copy a transform map whenever the function is called.

Basically the field map we need are always the same for every new transform map so we have a template transform map that we always just copy from and change only the import table. I couldn't seem to find any script that allow me to copy that template record.. Does anyone have clue whether it's doable in ServiceNow?

Thank you!

4 REPLIES 4

Deepak Kumar5
Kilo Sage

You can get Template by clicking on "more option" Toggle Template Bar but it have limitation.


You can use template to create a new Transform map and then load mapping through "sys_transform_entry" table using import.


brian_degroot
ServiceNow Employee
ServiceNow Employee

Hi Kiki,



You can use the following script in a UI action to create a copy of the transform map record along with the associated field map entries in its related list.



copy(current);


function copy(current) {


    current.name = "Copy of " + current.name;


    var gr = new GlideRecord('sys_transform_entry');


    gr.addQuery('map', current.sys_id);


    gr.query();


    var newMap = current.insert();


    while (gr.next()) {


        gr.map = newMap;


        gr.insert();


    }


}



Thank you,



Brian


dirktromp
Tera Contributor

I think brian.degroot has a good answer. My question is why do you want to copy it? It is already saved and if the data you are bringing in has the same colums, then you can apply the data to an existing 'import/staging' table and use the same transform over and over.


Geni1
Tera Contributor

The easiest way to do this is to go to the Transform map that you want, then right-click on the white border and click show xml. Save that xml file. Then modify the xml file to change the name and remove the sys_id. Then go to the transform map table and import the xml.