REST Import set mode

Bhupinder1
Giga Expert

I'm working on integration and successfully loaded data in import set table via REST API call for third party product. Since SOAP/REST transforms data in synchronous mode by default so I wanted to change the mode of the import set transform. I'm using schedule script to call the REST API method and loading data in ServiceNow import tables.

 

Regards

Bhupinder

1 ACCEPTED SOLUTION

Correct missed a function. But here is full piece-


var CreateAsynchImportSet = Class.create();


CreateAsynchImportSet.prototype = {



  createImportSet: function(tableName,description) {


  var isgr = new GlideRecord("sys_import_set");


  isgr.initialize();


  isgr.mode = "asynchronous";


  isgr.state = "loading";


  isgr.table_name = tableName;


  isgr.short_description = description;


  var is_id = isgr.insert();


  return isgr;


  },



  setStateTransform: function(setId) {


  //Mark the import set as Loaded


  setId.state = "loaded";


  setId.update();


  // transform the import set


  var t = new GlideImportSetTransformer();


  t.transformAllMaps(setId);


  return setId.state;


  }


}


View solution in original post

10 REPLIES 10

Bhupinder1
Giga Expert

Finally got it worked by creating script include and calling from business rule or script. Below is the code-



var CreateAsynchImportSet = Class.create();


CreateAsynchImportSet.prototype = {


  createImportSet: function(tableName,description) {


  var isgr = new GlideRecord("sys_import_set");


  isgr.initialize();


  isgr.mode = "asynchronous";


  isgr.state = "loading";


  isgr.table_name = tableName;


  isgr.short_description = description;


  var is_id = isgr.insert();


  return isgr;


  },


      type: 'CreateAsynchImportSet'


}


rodrigo16
Giga Contributor

This is very interesting. I also have data coming from a REST get method and synchronous transformation is giving me performance problems. I have tried out your solution and I am able to do the import of the data into the corresponding import table. However, once the loading of data is finished, I do not know how to trigger the transform to the target table from the script.



How do you do it? I have tried to change manually the state of the import set, but this did not work:


isgr.state = "loaded";


isgr.update();


Here you go-



var imp = new CreateAsynchImportSet();


var isId = imp.createImportSet("table name","Import Set Description");


// Logic for calling REST methods and loading data


imp.setStateTransform(isId);


Thanks Bhupinder, but you forgot to give us the implementation of the method "setStateTransform". It is not not in the code of the class "CreateAsynchImportSet" that you published... Maybe you did not copy the full implementation of the class in your post. Can you please share?