- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 09:50 AM - edited 07-24-2023 09:52 AM
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());
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:06 AM
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:
Create a Business Rule on the staging table (the child table in your case) to run when a record is updated.
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:06 AM
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:
Create a Business Rule on the staging table (the child table in your case) to run when a record is updated.
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.
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