Run a transform map when a record is updated in a certain Staging Table

saggi
Tera Contributor

We have a requirement to run transform map on a single record on staging table similar to out of box 

Transform synchronously Business rule which is on the sys import set table.We want to run it on the child table on update of a record.

 

How can we achieve that via script, similar to the below mentioned code .We want to correct certain field on the staging table and reprocess the 1 record.

 

var importSetGr = new GlideRecord("sys_import_set");
importSetGr.get(current.sys_import_set);
var importSetId = importSetGr.getUniqueValue();
var importSetRun = new GlideImportSetRun(current.sys_import_set);
var importLog = new GlideImportLog(importSetRun, "SOAP Transform");

var ist = new GlideImportSetTransformer();
ist.setLogger(importLog);
ist.setImportSetRun(importSetRun);
ist.setImportSetID(importSetId);
ist.setSyncImport(true);
ist.transformAllMaps(importSetGr, current.getUniqueValue());

 

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage
Mega Sage

Hi @saggi ,

 

To run a transform map on a single record in the staging table when it is updated, you can achieve this by using a Business Rule and GlideImportSetTransformer.

Here's how you can do it:

  1. Create a Business Rule on the staging table (the child table in your case) to run when a record is updated.

  2. In the Business Rule script, use GlideImportSetTransformer to transform the record. You can use the "update" event in the Business Rule to trigger the transformation when a record is updated.

  3. Set up the GlideImportSetTransformer to process the single record and correct certain fields before transforming.

Below is an example of how the Business Rule script might look like:

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the record is updated (this prevents the rule from running when the record is created)
    if (current.update()) {
        var importSetGr = new GlideRecord("sys_import_set");
        importSetGr.get(current.sys_import_set);
        var importSetId = importSetGr.getUniqueValue();
        var importSetRun = new GlideImportSetRun(current.sys_import_set);
        var importLog = new GlideImportLog(importSetRun, "SOAP Transform");

        var ist = new GlideImportSetTransformer();
        ist.setLogger(importLog);
        ist.setImportSetRun(importSetRun);
        ist.setImportSetID(importSetId);
        ist.setSyncImport(true);

        // Correct certain fields on the staging record here if needed
        // For example:
        // current.setValue('field_name', 'new_value');

        // Transform the single record
        ist.transformAllMaps(importSetGr, current.getUniqueValue());
    }
})(current, previous);

 

Replace 'field_name' with the actual field name you want to correct and 'new_value' with the correct value.

 

Thanks,

Ratnakar

View solution in original post

1 REPLY 1

Ratnakar7
Mega Sage
Mega Sage

Hi @saggi ,

 

To run a transform map on a single record in the staging table when it is updated, you can achieve this by using a Business Rule and GlideImportSetTransformer.

Here's how you can do it:

  1. Create a Business Rule on the staging table (the child table in your case) to run when a record is updated.

  2. In the Business Rule script, use GlideImportSetTransformer to transform the record. You can use the "update" event in the Business Rule to trigger the transformation when a record is updated.

  3. Set up the GlideImportSetTransformer to process the single record and correct certain fields before transforming.

Below is an example of how the Business Rule script might look like:

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the record is updated (this prevents the rule from running when the record is created)
    if (current.update()) {
        var importSetGr = new GlideRecord("sys_import_set");
        importSetGr.get(current.sys_import_set);
        var importSetId = importSetGr.getUniqueValue();
        var importSetRun = new GlideImportSetRun(current.sys_import_set);
        var importLog = new GlideImportLog(importSetRun, "SOAP Transform");

        var ist = new GlideImportSetTransformer();
        ist.setLogger(importLog);
        ist.setImportSetRun(importSetRun);
        ist.setImportSetID(importSetId);
        ist.setSyncImport(true);

        // Correct certain fields on the staging record here if needed
        // For example:
        // current.setValue('field_name', 'new_value');

        // Transform the single record
        ist.transformAllMaps(importSetGr, current.getUniqueValue());
    }
})(current, previous);

 

Replace 'field_name' with the actual field name you want to correct and 'new_value' with the correct value.

 

Thanks,

Ratnakar