Name

global.DataSourceLoader

Description

Loads Data using System Import Sets. Will clean up data source, transform map, import set, and import set table after import is complete. Takes a Data Source and Transform Map name Can specify to leave the map for future imports with a boolean value, if not specified the map will be deleted.

Script

gs.include("PrototypeServer");

var DataSourceLoader = Class.create();

DataSourceLoader.prototype = {
  initialize : function() {
  },

  load : function(/* Data Source */ source, /* Transform Map */ mapName) {
        this._load(source, mapName, true);
  },

  _load : function(/* Data Source */ source, /* Transform Map */ mapName, /* Delete Transform Map */ cleanMap) {
        var sourceGr = new GlideRecord('sys_data_source');
        sourceGr.addQuery('name', source);
        sourceGr.query();
        // if we have our data source continue
        if(!sourceGr.next()) {
           gs.print('Did not find Data Source ' + source);
           return;
        }

        var map = new GlideRecord('sys_transform_map');
        map.addQuery('name', mapName);
        map.query();
        // if we have a map we can now load and run the transform
        if(!map.next()) {
           gs.print('Did not find Transform map ' + mapName);
           return;
        }
  
        gs.print('Loading Import Set ' + source);
        var loader = new GlideImportSetLoader();
        var importSetGr = loader.getImportSetGr(sourceGr);
        var ranload = loader.loadImportSetTable(importSetGr, sourceGr);

        if(!ranload) {
           gs.print('Failed to load import set ' + source);
           return;
        }

        gs.print('Running Transform map ' + map.name);
        var t = new GlideImportSetTransformer();
        t.setMapID(map.sys_id);
        t.transformAllMaps(importSetGr);
        
        // Clean up Import
        var cleaner = new ImportSetCleaner(importSetGr.table_name);
        cleaner.setDataOnly(true);
        cleaner.setDeleteMaps(cleanMap);
        cleaner.clean();
  }

}

Sys ID

f72885290a0a0b4d01957352e8a29e31

Offical Documentation

Official Docs: