Master Data Upload via Catalog Item

General Add comments

Do you want to perform Master Data uploads via a Catalog Item?

ServiceNow gives you the option to make use of the following capabilities:

  • Catalog Items
  • UI Page
  • UI Macro
  • Workflows
  • Script Actions
  • Script Includes
  • Data Sources
  • Import Sets
  • Transform Maps
  • Notifications
  • Reports

In our use case, we make use of these components for the upload of CI’s and Assets.

Preparation per category

  1. Create a template for the upload of CI’s and Assets
  2. Make the import set and transform map
  3. Verify the upload of CI’s and Assets

Create a new catalog item for the mass upload of CI’s/Assets

  1. With the variables: Requested for, Category, Template, Reporting results, attachment
  2. Make sure you add the attachment with the master data to be uploaded in the correct template
    1. UI Page for download the correct template based on the selected category
    2. UI Macro for uploading the attachment
  3. Create a catalog client script OnSubmit
    1. To check if the attachment is added
    2. To check if there is only one attachment with the correct template and extension

Create a new workflow for the Catalog item

Add the following steps:

  1. Create Datasource, Scheduled Import and Run Transformation (Run Script that calls a Script Action)

    function dataSourceImport(){
    gs.eventQueue('', current, current.variables.import_category, current.variables.requested_for.user_name);
  2. Create Exception Report (Run Script that calls a Script Include)

    function createExceptionReport(){
    var result = new MassDataLoadsUtil().phSendExceptionReport(current.variables.requested_for, current.variables.import_category, current.variables.report_results, current.variables.email_to, current.variables.import_set);

The called script actions will make use of a script include

  1. Create Datasource
    //create the data source record and copy the attachment from the catalog item
    var ds = new GlideRecord('sys_data_source');
    ds.initialize(); = dataSource;
    ds.import_set_table_name = importTable;
    ds.import_set_table_label = importLabel;
    ds.type= dsType;
    ds.format = dsFormat;
    ds.file_retrieval_method = dsRetrievalMethod;

    if (dsFormat == 'Excel') {
    ds.sheet_number = dsSheetNr;
    ds.header_row = dsHeaderRow;
    } else if (dsFormat == 'CSV'){
    ds.delimiter = dsDelimiter;

    var NewDataSource = ds.insert();

    //copy attachment from the catalog item to the dataSource

  2. Schedule Import and Run Transformation
    //Load the data into an import set and transform this based on the related transform map(s)
    var sourceGr = new GlideRecord('sys_data_source');
    sourceGr.addQuery('sys_id', source);

    // if we have our data source continue
    if(! {

    //create the import set and load this with the data from the data source
    var loader = new GlideImportSetLoader();
    var importSetGr = loader.getImportSetGr(sourceGr);
    var ranload = loader.loadImportSetTable(importSetGr, sourceGr);

    if(!ranload) {
    //Failed to load import set

    //Running Transfom map(s) of the related import set
    var mapName = 'IMP TTM Load Cis and Assets: ' +importCategory;
    var importSetRun = new GlideImportSetRun(importSetGr.sys_id);
    var importLog = new GlideImportLog(importSetRun, mapName);
    var ist = new GlideImportSetTransformer();

  3. Create Exception Report
    //create a list report based on the input variables (all results or only errors) per category
    var grRpt = new GlideRecord('sys_report');
    grRpt.title = sTitle;
    grRpt.table = sTable;
    grRpt.type = sType;
    grRpt.filter = sCondition;
    grRpt.field_list = sFields;
    grRpt.orderby_list = sOrder;
    grRpt.user = inRequestedFor;
    grRpt.roles = '';
    var rptID = grRpt.insert();
  4. Send Notification with the Exception Report
    //execute this report direct and send the results to the related users/groups with the report subject and body text
    var userID = sEmails;

    var grSchRpt = new GlideRecord('sysauto_report');
    grSchRpt.address_list = sEmails;
    grSchRpt.user_list = userID;
    grSchRpt.output_type = sOutputType; = sRptID;
    grSchRpt.run_type = sRunType;
    grSchRpt.report_title = sSubject;
    grSchRpt.report_body = sBody; = 'Auto Sending of ' +;
    var schRptID = grSchRpt.insert(); // since it is a "once" schedule, it will be executed right away

By following above steps you should be able to trigger the upload via a catalog item!

Leave a Reply