Load Data. Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 06:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 12:38 AM
Hi,
are you saying each time you wish to create new import set table?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 01:31 AM
Only once but using script. And use this table after.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 02:09 AM
Hi,
If you wish to create table only once and use it multiple times later then why to use script to create table?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 02:44 AM
Hi,
Here is the path to find all import set tables - System Definition -> Tables -> query for Import Set.
You'd find the list of import set tables
Mark it Helpful, if it works.
Thank you
SS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 03:14 AM
Hi,
I've been using the below Script Include to load data programmatically for several projects, you can try this.
Few things you need to change here -
- keep the excel or CSV file in the Data source table
- make sure the import set table name is updated in the data source record.
- 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)
- 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.)
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();
},
};
Regards,
SS
Please mark an appropriate response as correct if my answer replied to your question.