Data Import Using Service Catalog

neethu4
Giga Expert

Hi All,

I want to create a catalog item which will help to import the file to CMDB table.My thought is on submit of the the request trigger the data source and pass the attachment to it.

But don't know how to achieve it.

Please let me know if any suggestion on this

Thanks,

Neethu

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Neethu,



That's correct.


1) Have business rule after insert on RITM table which runs only for that particular Catalog Item.


2) Have a data source, transform map and field map created as usual. coalesce etc will be present


3) Have scheduled import created with this data source with active= false, run as administrator since it will be triggered from script. In left nav type Scheduled Imports and create new


4) in the business rule condition check whether the RITM has attachment then only run the business rule and have following script



Business rule condition:


current.hasAttachments()


//extra check you can have is whether it is csv or xls based on data source attachment file type



Business rule script:



var dataSourceSysId = ''; // sys_id of the data source you created in step 2


var schImp_GR = new GlideRecord('scheduled_import_set');


schImp_GR.addQuery('data_source',dataSourceSysId);


schImp_GR.query();


if(schImp_GR.next()){


gs.executeNow(schImp_GR); // use this if it is in scoped app


//SncTriggerSynchronizer.executeNow(schImp_GR); // if in non-scope app i.e. global



// the above 2 lines will start the import process, etc automatically


}



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

25 REPLIES 25

Hi Ankur,

When we are adding attachment to the Data-source,i am getting Connection Url error.Could you please suggest how to resolve this issue.

 

Thanks,

Pavani. 

Hi Uma,

Can you share what error you are getting in logs?

Regards
Ankur

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

Is there way we can validate the loaded file before executing it

Hi Ankur,

 

Thank you very much for providing such a good idea.

I was wondering, since the attached file is related to the RITM, how the BR and the import set would know which file needs to be processed as part of the import.

Usually, when a data source is created the file is attached to it, but in this case the file is not attached to the scheduled import but to the RITM.

 

Regards,

Max

sunil4050
Giga Contributor

Hello Ankur,

 

I too have similar requirement. I am creating a SR from catalog and in RITM BR i have added the following code to create a data source and copy the attachment to it. Data source is created but attachment is not copied. Could you please check and let me know 

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here
gs.addInfoMessage("I am in Business Rule");

var DataSource = new GlideRecord('sys_data_source');
DataSource.initialize();

var importSetTableName = "u_sspn_sr";

var transformMapIDs = "1bc7c800db731300a7700d53ca96194e"; //Use a comma to specify multiple transform maps

var applicatonScope = "Global";

DataSource.name = "Bulk Creation of SR"; //Feel free to rename this as appropriate
DataSource.import_set_table_name = importSetTableName;
DataSource.file_retrieval_method = "Attachment";
DataSource.type = "File";
// current.format = "Excel"; // For Excel Files

DataSource.format = "CSV"; // For CSV Files
DataSource.header_row = 1;
DataSource.sheet_number = 1;
DataSource.sys_package.setDisplayValue(applicatonScope);
DataSource.sys_scope.setDisplayValue(applicatonScope);
var dataSourceID = DataSource.insert();


GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', 'dataSourceID');
DataSource.update();

gs.log("Data Source ID === " + dataSourceID);
gs.log("Data Source Created");

new global.EmailFileImportUtils().scheduleImport(dataSourceID, transformMapIDs);

})(current, previous);

 

There is a script include "EmailFileImportUtils" to schedule a job and do the transform.... Please let me know if there is any alternative way to add attachment to data source from BR