Scheduled Import Set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 10:18 AM
Hello,
My company currently inserts a csv into a ServiceNow table using https://surgerypartnersdev.service-now.com/api/now/table/insert_table_name. I am wanting to create a scheduled import set that receives a csv file from an external source and automatically transforms and maps the table. We are wanting to use this method vs our current one so we can coalesce on field and not continuously update this table unnecessarily.
Honestly, looking for an article or video that explains how to do this with an external source and not with the file retrieval method being an attachment.
**** EDIT **** still needing help with this
Today we are posting json data to the Service Now endpoint https://surgerypartnersdev.service-now.com/api/now/table/insert_table_name so the data is currently going directly into the table. We are wanting to automatically transform and map the data and then insert the data into the table. Is there a way to do this via an endpoint similar to how we are directly posting to the table today?
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:11 PM
Hi
I've been using the below steps for a long time, try this.
System Import Sets -> Data Source -> create a data source -> set the "File Retrieval method" as per your requirement. Then do the changes as mentioned below.
- make sure the import set table name is updated in the data source record.
- put the below script into a Script Include and you can call it from any server-side script (such as - inbound action, BR, scheduled job etc.)
- In the script, dataSourceID is the sys_id of that data source (that you want to load)
- create a transform map beforehand.
- In the script, transformMapID is the sys_id of the transform map (that you want to use to map and load data)
var EmailFileImportUtils = Class.create();
EmailFileImportUtils.prototype = {
scheduleImport: function(dataSourceID, transformMapID) {
var schRec = new GlideRecord("sys_trigger");
schRec.name = "Load Data Source: " + dataSourceID;
schRec.trigger_type = 0; // Run Once
schRec.script = "new global.EmailFileImportUtils().loadImportSet('" + dataSourceID + "', '" + transformMapID + "')";
var nextAction = new GlideDateTime();
nextAction.addSeconds(30); // 30 seconds should be enough time however this can be changed.
schRec.next_action = nextAction;
schRec.insert();
},
loadImportSet: function(dataSourceID, transformMapID) {
// Get Datasource Record
var dataSource = new GlideRecord("sys_data_source");
dataSource.get(dataSourceID);
// Process data source file
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(dataSource);
var ranload = loader.loadImportSetTable(importSetRec, dataSource);
importSetRec.state = "loaded";
importSetRec.update();
// Transform import set
var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id, transformMapID);
transformWorker.setBackground(true);
transformWorker.start();
},
};
Please mark an appropriate response as correct if my answer replied to your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 01:36 PM
Today we are posting json data to the Service Now endpoint https://surgerypartnersdev.service-now.com/api/now/table/insert_table_name so the data is currently going directly into the table. We are wanting to automatically transform and map the data and then insert the data into the table. Is there a way to do this via an endpoint similar to how we are directly posting to the table today?