Multiple transform maps should not trigger

ThatiV
Tera Contributor

Hi,

I have a requirement involving a catalog item in the portal, which is already implemented for bulk upload. When we select the CI class variable from the portal, the respective transform map should run. However, currently, if we have 12 rows in the template, every transform map runs 12 times, resulting in a total of 17 TMs * 12 (number of rows in the template). This means if we have 1000 records, each TM runs 1000 times. It is not necessary for all transform maps to run; only the one related to the selected class should run when we import data from the bulk import catalog.

Can anyone suggest me to make this possible please.

1 ACCEPTED SOLUTION

Thanks for the info.

I'd replace your 'Trigger Transformation' with the following segment

var importSetRun = new GlideImportSetRun(importSetRecSysID);
    var transformer = new GlideImportSetTransformer();
    transformer.setImportSetRun(importSetRun);
	transformer.setMapID('sys_id_of_map_here');
    transformer.transformAllMaps(importSet);

The setMapID is where you want to define the sys_id of the ma based on your Type of CI choice list. You could do this with an object

	//Access your type of CI variable, and get it's value
	var choiceValue = grRitm.variables.type_of_ci;

	//left 'key' is the choice options for the variable,
	//right 'value' is your map IDs
	var choiceTransformMapLookup = {
		'ssbd' : 'f72885290a0a0b4d01957352e8a29e31',
		'kiosk' : 'sys_id',
		'biopod' : 'another sys id'
	}
    
	var importSetRun = new GlideImportSetRun(importSetRecSysID);
    var transformer = new GlideImportSetTransformer();
    transformer.setImportSetRun(importSetRun);
	transformer.setMapID(choiceTransformMapLookup[choice_value]);
    transformer.transformAllMaps(importSet);

 

View solution in original post

3 REPLIES 3

Kieran Anson
Kilo Patron

Hi,

Can you share details of this catalog item? Are you triggering a flow/workflow to parse the attachment and import data into an import set? Can you share your code for us to review?

 

@Kieran Anson 
Thanks for your response!!
We are triggering via flow designer with to run the data source and the respective TM's

here is the script from flow designer

    (function execute(inputs, outputs) {
        // -------------- Delete the attachments from data source --------------------
        var dataSource = gs.getProperty('ama.create.update.ci.data.source');
       
        var gsa = new GlideSysAttachment();
        var grSysAttach = new GlideRecord('sys_attachment');
        grSysAttach.addQuery('table_name', 'sys_data_source');
        grSysAttach.addQuery('table_sys_id', dataSource);
        grSysAttach.query();
        while (grSysAttach.next()) {
           grSysAttach.deleteMultiple();
        }
        // -------------- Copy the attachments from data source -------------------------
        gs.sleep(2000); // To let the deletion complete
        GlideSysAttachment.copy('sc_req_item', inputs.ritmSysID, 'sys_data_source', dataSource);
        // --------------- Run Data Source -------------------------
        var importSetRecSysID = "";
        var importSetRec = "";
        var grDataSource = new GlideRecord('sys_data_source');
        if (grDataSource.get(dataSource)) {
            var loader = new GlideImportSetLoader();
            var importSetRec = loader.getImportSetGr(grDataSource);
            var ranload = loader.loadImportSetTable(importSetRec, grDataSource);
            importSetRec.state = "loaded";                      
            importSetRec.update();
            importSetRecSysID = importSetRec.getUniqueValue();
            importSetRec = importSetRec.getDisplayValue();
        }
        // ------------- backfillImportSetdata ---------------------
        var grRitm = new GlideRecord('sc_req_item');
        if (grRitm.get(inputs.ritmSysID)) {
            var grImpSet = new GlideRecord('u_aspen_cmdb_create_update_units');
            grImpSet.addEncodedQuery('sys_import_set=' + importSetRecSysID);
            grImpSet.query();
            while (grImpSet.next()) {
                grImpSet.sys_created_by = grRitm.opened_by;
                grImpSet.sys_updated_by = grRitm.opened_by;
                grImpSet.u_account = grRitm.variables.account.getDisplayValue();
                grImpSet.u_sold_product = grRitm.variables.sold_product.getDisplayValue();
                grImpSet.u_unit_model_id = grRitm.variables.unit_model_id.getDisplayValue();
                grImpSet.u_location = grRitm.variables.location.getDisplayValue();
                grImpSet.u_install_date = grRitm.variables.install_date;
                grImpSet.u_install_status = grRitm.variables.install_status;
                grImpSet.u_operational_status = grRitm.variables.operational_status;
                //grImpSet.autoSysFields(false);
                grImpSet.update();
            }
            importSetRec.sys_created_by = grRitm.opened_by;
            importSetRec.sys_updated_by = grRitm.opened_by;
            //importSetRec.autoSysFields(false);
            importSetRec.update();
        }
        // ------------- Trigger Transformation --------------------        
       
        var grImpSet = new GlideRecord('sys_import_set');
        if (grImpSet.get(importSetRecSysID)) {
            var transformer = new GlideImportSetTransformer();
            transformer.transformAllMaps(grImpSet);
        }

        // ------------- Error parsing -----------------------------
        var transMapErrorCount = 0;
        var importInfo = 'Import set : ' + importSetRec + '\n';
        var grImpLogErr = new GlideRecord('import_log');
        grImpLogErr.addQuery('import_set', importSetRecSysID);
        grImpLogErr.addQuery('level', '2');
        grImpLogErr.query();
        if (grImpLogErr.next()) {
            transMapErrorCount++;
            importInfo += "Error in transform map : " + grImpLogErr.message + "\n";
        }
        importInfo += "------------------------\n\n" + "For more details of CI load, go to corresponding transform history.";
        // -------------------- Set action output ---------------
        outputs.comments = importInfo;
        outputs.error = transMapErrorCount;

    })(inputs, outputs)



ThatiV_0-1739851815149.png

If you see the piece of below code 
==============================
var grImpSet = new GlideRecord('sys_import_set');
if (grImpSet.get(importSetRecSysID)) {
var transformer = new GlideImportSetTransformer();
transformer.transformAllMaps(grImpSet);


They have used the object called “transformAllMaps.” Instead of this, I need to trigger the TM based on the selection of the CI type from the portal. The respective TM should trigger based on the selected CI.

Could you please suggest how I can proceed to trigger the TM based on the selected CI from the portal?


FYI: The “on before” script is already written based on the CI selected in the template.

Thanks for the info.

I'd replace your 'Trigger Transformation' with the following segment

var importSetRun = new GlideImportSetRun(importSetRecSysID);
    var transformer = new GlideImportSetTransformer();
    transformer.setImportSetRun(importSetRun);
	transformer.setMapID('sys_id_of_map_here');
    transformer.transformAllMaps(importSet);

The setMapID is where you want to define the sys_id of the ma based on your Type of CI choice list. You could do this with an object

	//Access your type of CI variable, and get it's value
	var choiceValue = grRitm.variables.type_of_ci;

	//left 'key' is the choice options for the variable,
	//right 'value' is your map IDs
	var choiceTransformMapLookup = {
		'ssbd' : 'f72885290a0a0b4d01957352e8a29e31',
		'kiosk' : 'sys_id',
		'biopod' : 'another sys id'
	}
    
	var importSetRun = new GlideImportSetRun(importSetRecSysID);
    var transformer = new GlideImportSetTransformer();
    transformer.setImportSetRun(importSetRun);
	transformer.setMapID(choiceTransformMapLookup[choice_value]);
    transformer.transformAllMaps(importSet);