Notifications

28 views

Description

All import sets created for Import SET API calls are "Synchronous". What this means is that as an import set row is created, it is transformed immediately.

To prevent immediate transform the import set can be made "Asynchronous". 

Resolution

This can be achieved as follows:

  1. Create a "Before" insert business rule on the sys_import_set table with a conditional check on the Import set table (table_name) that should not be transformed synchronously.
  2. Under actions, add 'Mode' to 'Asynchronous'.
  3. Create a Scheduled job that runs every few minutes and transforms the 'asynchronous' import set, with the following script and set it to run 'Periodically'.

There is an OOB Scheduled Script Execution "Asynchronous Import Set Transformer", you can use that as a guideline and change line 8 (igr.addQuery("state", "loaded")) and replace it with the following 2 lines: 

igr.addQuery("table_name", "the staging table name");
igr.addQuery("state", "loading");

 

The complete Script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
transformAsyncIset();

function transformAsyncIset() {
    var igr = new GlideRecord("sys_import_set");
    igr.addQuery("mode", "asynchronous");
    igr.addQuery("table_name", "STAGING_TABLE_NAME");
    igr.addQuery("state", "loading");
    igr.query();
    while (igr.next()) {
        sTransform(igr);
    }
}

function sTransform(igr) {
    var mapsList = getMap(igr.table_name);

    var t = new GlideImportSetTransformerWorker(igr.sys_id, mapsList);
    t.setProgressName("Transforming: " + igr.number);
    t.setBackground(true);
    t.start();
}

function getMap(sTable) {
    var mapGR = new GlideRecord("sys_transform_map");
    mapGR.addQuery("source_table", sTable);
    mapGR.addActiveQuery();
    mapGR.query();

    var mapsList = [];
    while (mapGR.next())
        mapsList.push(mapGR.getUniqueValue());

    return mapsList.join();
}

 

Article Information

Last Updated:2019-10-31 09:24:06
Published:2019-10-31