call import set using workflow

amitgaur
Tera Contributor

Hi,

I need to achieve two things:

1> Call a Import set from catalog item workflow.

2> This import set should create as many requested item (RITM) records in servicenow as there are rows in the attached excel file during the time of ordering the catalog item.

Any code that can achieve this?

1 ACCEPTED SOLUTION

Hi Amit,



Sample script below:



2) Copy the attachment from RITM to the data source record using GlideSysAttachment() copy


GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', '<dataSourceSysId>');



3) Trigger the scheduled data import from workflow script and it should start the transform map etc



var exportGr = new GlideRecord("scheduled_import_set");


      exportGr.addQuery("sys_id", "<RecordSysId>"); // sys_id of the record which you will be creating for scheduled data import


      exportGr.query();


      if (exportGr.next()) {


              gs.executeNow(exportGr); // this is for scoped app


          // SncTriggerSynchronizer.executeNow(schImp_GR); // this is for non scoped app


      }



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Amit,



I assume you want to run data source and load some records.


1) Create Scheduled Data Import for this data source and make this active false


2) Copy the attachment from RITM to the data source record using GlideSysAttachment() copy


3) Trigger the scheduled data import from workflow script and it should start the transform map etc



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,


Thanks for your response. I know this process but was looking for the code that can help me. Could you please provide a sample script (need not to be exact) for the below two points :


2) Copy the attachment from RITM to the data source record using GlideSysAttachment() copy


3) Trigger the scheduled data import from workflow script and it should start the transform map etc


Hi Amit,



Sample script below:



2) Copy the attachment from RITM to the data source record using GlideSysAttachment() copy


GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', '<dataSourceSysId>');



3) Trigger the scheduled data import from workflow script and it should start the transform map etc



var exportGr = new GlideRecord("scheduled_import_set");


      exportGr.addQuery("sys_id", "<RecordSysId>"); // sys_id of the record which you will be creating for scheduled data import


      exportGr.query();


      if (exportGr.next()) {


              gs.executeNow(exportGr); // this is for scoped app


          // SncTriggerSynchronizer.executeNow(schImp_GR); // this is for non scoped app


      }



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

That worked perfectly. Thanks