Copy a tranform map using script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 06:38 PM
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!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 03:12 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 03:50 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 04:33 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 06:36 AM
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.