How to run a Transform Map via script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2024 12:25 AM
Hello All,
I want to run the Transform Map using a script include.
Can anyone suggest the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2024 12:43 AM - edited ‎01-15-2024 12:49 AM
You can run a Transform Map through a script by using the `sys_script_include` GlideRecord to interact with the `TransformMap` class. Below is an example of how you might do this within a Script Include:
var TransformMapScript = Class.create();
TransformMapScript.prototype = {
initialize: function() {
},
// Function to run the specified Transform Map
runTransformMap: function(sourceTable, transformMapName) {
// Instantiate the GlideRecord for the Import Set Row table (sourceTable)
var gr = new GlideRecord(sourceTable);
gr.query(); // Add any necessary query filters to select the appropriate records
// Instantiate the TransformMap class
var tm = new GlideTransformMap();
// Get the sys_id of the Transform Map by its name
var transformMapSysId = this.getTransformMapSysId(transformMapName);
if (transformMapSysId) {
// Run the Transform Map for each record in the Import Set
while (gr.next()) {
tm.transformRecord(gr, transformMapSysId);
}
} else {
gs.error("Transform Map not found: " + transformMapName);
}
},
// Helper function to get the sys_id of a Transform Map by its name
getTransformMapSysId: function(transformMapName) {
var transformMapGr = new GlideRecord('sys_transform_map');
transformMapGr.addQuery('name', transformMapName);
transformMapGr.query();
if (transformMapGr.next()) {
return transformMapGr.sys_id.toString();
}
return null;
},
type: 'TransformMapScript'
};
// Example usage:
// var tms = new TransformMapScript();
// tms.runTransformMap('u_import_set_table', 'Your Transform Map Name');
In this example, `TransformMapScript` is a Script Include that contains a method `runTransformMap` which takes two parameters: the name of the source table (`sourceTable`) and the name of the Transform Map (`transformMapName`). The method retrieves the Transform Map's `sys_id` using the helper function `getTransformMapSysId` and then iterates over each record in the source table, applying the Transform Map to each record using the `transformRecord` method of the `GlideTransformMap` class.
Please note that running a Transform Map via a script should be done with caution, as it can have significant effects on your data. Additionally, make sure to add appropriate error handling and logging as needed for your use case.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2024 12:47 AM