How to pass requested item Sys_id in import set table.

keshav77
Tera Contributor

Hi All,

 

I am working on one project where I am trying to run tranform through catalog and get the tranformmap error logs under the particular filed of requested item. then we run work flow if there is some error message of that transform map in that requested item filed we will cancell the requested item.

 

I have created the business rule to create dynamic data source and import set run but the current issue I am not able to pass sys_id of the requested item into the import set refernce field which refernce to RITM.

 

after what  I am looking to pass the error of tranform script to pass them in particular filed in ritm.

kindly help me this if there any approach of doing that please let me know.

below the business rule that create data source am import.

(function executeRule(current, previous /* null when async */) {
  gs.info('--- Script Execution Started ---');

  // Step 1: Create a new Data Source
  var ds = new GlideRecord('sys_data_source');
  ds.initialize();
  ds.name = "Dynamic_" + gs.nowDateTime();
  ds.import_set_table_name = 'u_myspecial';
  ds.type = 'File';
  ds.format = 'Excel';
  ds.file_retrieval_method = 'Attachment';
  ds.header_row = 3;
  ds.sheet_number = 1;
  var dataSourceSysId = ds.insert();
  gs.info('[Step 1] Data Source created: ' + dataSourceSysId);

  // Step 2: Copy the attachment
  var at = new GlideSysAttachment();
  var newAttachmentSysId = at.copy(
    'sc_req_item',
    current.getUniqueValue(),
    'sys_data_source',
    dataSourceSysId
  );
  if (!newAttachmentSysId) {
    gs.error('[Step 2] Attachment copy failed for RITM: ' + current.number);
    return;
  }
  gs.info('[Step 2] Attachment copied: ' + newAttachmentSysId);

  var dsUpdate = new GlideRecord('sys_data_source');
  if (dsUpdate.get(dataSourceSysId)) {
    dsUpdate.attachment = newAttachmentSysId;
    dsUpdate.update();
    gs.info('[Step 2] Data Source updated with attachment.');
  } else {
    gs.error('[Step 2] Unable to update Data Source.');
    return;
  }

  // ✔ Step 3: Load the Data Source as GlideRecord
  var grDataSource = new GlideRecord('sys_data_source');
  if (!grDataSource.get(dataSourceSysId)) {
    gs.error('Failed to fetch Data Source record: ' + dataSourceSysId);
    return;
  }

  // Step 4: Import using loader
  var loader = new GlideImportSetLoader();
  var importSetRec = loader.getImportSetGr(grDataSource);
  var ranLoad = loader.loadImportSetTable(importSetRec, grDataSource);
  if (!ranLoad) {
    gs.error('Import load failed.');
    return;
  }
  importSetRec.state = 'loaded';
  importSetRec.update();
  gs.info('Loaded Import Set: ' + importSetRec.getUniqueValue());

  // Step 5: Run transform via Transform Worker
  var importSetRecSysID = importSetRec.getUniqueValue();
  var transformWorker = new GlideImportSetTransformerWorker(importSetRecSysID,'059f64d4c37a6650478af73ed40131ec');
  transformWorker.setBackground(true);
  transformWorker.start();
})(current, previous);
@Ankur Bawiskar  any suggestion or any approch to acchive this
4 REPLIES 4

pavani_paluri
Giga Guru

Hi @keshav77 ,

 

To access RITM in import set, Please try creating a new field on import set table and try populating in before transform start and after loading. This way you can have ritm sysid and In your Transform Script (in the Transform Map), add a script that checks for errors and logs them to a field on the RITM.

 

In the flow or workflow of RITM, add condition to check whether error fields has data or not. Based on result you can cancel the RITM.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P

I am trying to do that but it is not passing the. Ritm Sysid in transform map

Are you capturing the ritm in any field in import set?

Yes through the share business rule I am trying to capture the current record sysid by it not passing in importset table field