How to automate loading of data into import set and transforming into target table

SNOW Learner09
Tera Guru

I am trying to import XML file data using Import set Data source & Transform maps. With manual loading of data into import set table and transforming manually working fine to create the data in target table. However, I want it as automated process using events and script action. Script Action is triggering with attachment uploaded event but seeing the below error in logs and data is not loading into import set table as well. Please help to understand what is wrong here and how to automate the loading of data and transform map as well. 

 

My code in Script Action:

 

// to load the data from attachment to import set table

 

var loader = new GlideImportSetLoader();

var importSetRec = loader.getImportSetGr(current);

var ranload = loader.loadImportSetTable(importSetRec, current);

importSetRec.state = "loaded";

importSetRec.update();

 

// code to run transform map and insert the data into target table

 

var test = new GlideImportSetTransformerWorker('<sys_id of import set table>','<sys_id of transform map>');

test .setProgressName("Transforming: " +  XML_file_transform);

test .setBackground(true);

test .start();

 

Error:

JavaScript evaluation error on:
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(current);
var ranload = loader.loadImportSetTable(importSetRec, current);
importSetRec.state = "loaded";
importSetRec.update();

 

Root cause of JavaScriptException: java.lang.NullPointerException
: java.lang.NullPointerException: com.glide.system_import_set.ImportSetLoader.getImportSetTableName(ImportSetLoader.java:115)
com.glide.system_import_set.ImportSetLoader.createImportSetGr(ImportSetLoader.java:154)
com.glide.system_import_set.ImportSetLoader.getImportSetGr(ImportSetLoader.java:146)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

1 ACCEPTED SOLUTION

SNOW Learner09
Tera Guru

Hi Community users, 

 

This may be useful if anyone is looking for similar solution. I could complete the above task and resolve above error.

Data source: XML file

Details: This task is about once xml file is attached (from integration, 3rd party app etc) need to load the data into import set table and running the transform map through script action (attachment.uploaded) event firing. Use above code if someone is looking on similar task.

 

var grDataSource = new GlideRecord('sys_data_source');
if (grDataSource.get([Data source sys ID])) {
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(grDataSource);
var ranload = loader.loadImportSetTable(importSetRec, grDataSource);
importSetRec.state = "loaded";
importSetRec.update();
gs.info('Unique value is: ' + importSetRec.getUniqueValue());
var importSetRecSysID = importSetRec.getUniqueValue();
var transformWorker = new GlideImportSetTransformerWorker(importSetRecSysID, [Transform Map Sys ID]);
transformWorker.setBackground(true);
transformWorker.start()

View solution in original post

3 REPLIES 3

SNOW Learner09
Tera Guru

Hi Community users, 

 

This may be useful if anyone is looking for similar solution. I could complete the above task and resolve above error.

Data source: XML file

Details: This task is about once xml file is attached (from integration, 3rd party app etc) need to load the data into import set table and running the transform map through script action (attachment.uploaded) event firing. Use above code if someone is looking on similar task.

 

var grDataSource = new GlideRecord('sys_data_source');
if (grDataSource.get([Data source sys ID])) {
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(grDataSource);
var ranload = loader.loadImportSetTable(importSetRec, grDataSource);
importSetRec.state = "loaded";
importSetRec.update();
gs.info('Unique value is: ' + importSetRec.getUniqueValue());
var importSetRecSysID = importSetRec.getUniqueValue();
var transformWorker = new GlideImportSetTransformerWorker(importSetRecSysID, [Transform Map Sys ID]);
transformWorker.setBackground(true);
transformWorker.start()

Hi @SNOW Learner09 

 

Thank you so much for posting the solution. I was running through a similar issue and stumbled upon your post. Your solution works perfect. Thanks again.

Community Alums
Not applicable

Thank you! Came into a similar situation.