Need to run Transform Map or Robust transform engine on record insertion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 11:03 AM
Hi All,
Please help me to achieve the below requirement.
1. CMDB data is pushed as JSON in a Scripted Rest API POST method.
2. Needs to parse the JSON and to store in a Import Set table.
3. After record insertion Transform Map or Robust transform Engine needs to get executed to store in different CMDB tables.
Pain point:
1. I have tried and achieved upto storing the data in import set table using GlideRecord(), But Transform map is not executing automatically.
2. Can we use Data Source any way to process? coz I'm using scripted rest api to get data which I dont know how to take this using Data Source.
Thanks in Advance : )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 11:28 AM
You can use below code to run transform script after you have loaded data to import table
// impset = your import set GlideRecord
// transformMap = your transfrom map GlideRecord
var transformMapSysID = ''; //Your transfrom map sys_id here
var transformMap = new GlideRecord('sys_transform_map');
transformMap.get(transformMapSysID);
var importSetSysID = ''; //Your import set sys_id here
var impset = new GlideRecord('sys_import_set');
impset.get(importSetSysID);
var t = new GlideImportSetTransformerWorker(impset.sys_id, transformMap.sys_id);
t.setProgressName("Transforming: " + impset.number + " using map " + transformMap.name);
t.setBackground(true);
t.start();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 12:18 PM
Hi @Vishnu kumar R ,
Hope you are doing great.
To parse and store this JSON data in an Import Set table, you can follow these steps:
Create a Scripted REST API in ServiceNow to receive the JSON data. This API should handle the POST method and extract the JSON payload.
Within the Scripted REST API, use the ServiceNow API's built-in JSONParser class to parse the JSON data and extract the relevant information.
Instantiate a new Import Set table record using the GlideImportSet API, and set the extracted data fields accordingly.
var importSetGR = new GlideImportSet();
importSetGR.initialize();
importSetGR.setValue('field_name', parsedData.field);
importSetGR.setValue('another_field', parsedData.anotherField);
// Set other relevant fields as needed
importSetGR.insert();
4. After inserting the record into the Import Set table, Create a Transform Map that maps the Import Set table fields to the corresponding fields in the target CMDB tables. Configure the Transform Map to run the Transform Script upon insertion of records from the Import Set table.
(function runTransformScript(source, target, map, log, logWrapper) {
// Transform and map fields from the source (Import Set table) to the target (CMDB table)
target.field_name = source.getValue('field_name');
target.another_field = source.getValue('another_field');
// Map other fields as required
// Return true to continue with the transformation process
return true;
})(source, target, map, log, logWrapper);
Regards,
Riya Verma