Triggering workflow from on complete transfrom map script issue

keshav77
Tera Contributor

Hi All,

I am trying  the workflow  from on complete transfrom map script currently what is happening it taking all record from the import set table  hold. it is not taking from the current import set table record only why this is happening can any one help me with this below is my scripts--

 

(function runTransformScript(source, map, log, target) {

    gs.info("Transform Map onComplete script triggered");

    try {
        var importSetId = map.getImportSetID();

        var wflw = new Workflow();
        var wfId = wflw.getWorkflowFromName('END POINT TO API');

        if (wfId) {
            var wfInputs = {
                import_set_id: importSetId
            };

            var started = wflw.startFlow(wfId, target, wfInputs); /

            gs.info("Workflow startFlow result: " + started);

            if (!started) {
                gs.info("Trying startFlowRetroactive...");
                var retroStarted = wflw.startFlowRetroactive(wfId, target, wfInputs);
                gs.info("Workflow startFlowRetroactive result: " + retroStarted);
            }
        } else {
            gs.error("Workflow 'END POINT TO API' not found.");
        }

    } catch (e) {
        gs.error("Error starting workflow: " + e.message);
    }

})(source, map, log, target);
 
 
 
here is runscript--
 
 
 
var importSetId = workflow.inputs.import_set_id;

if (!importSetId) {
    gs.error("No import_set_id passed to workflow.");

}

var grendpoint = new GlideRecord('u_api_inventory_data_upload');
grendpoint.addQuery('import_set', importSetId);
grendpoint.query();

while (grendpoint.next()) {
    try {
        var grapi = new GlideRecord('cmdb_ci_api');
        grapi.initialize();
        grapi.name = grendpoint.u_api_name;

        var newSysId = grapi.insert();
        if (newSysId) {
            gs.info("Inserted cmdb_ci_api record with sys_id: " + newSysId + " for API: " + grendpoint.u_api_name);
        } else {
            gs.warn("Failed to insert cmdb_ci_api record for API: " + grendpoint.u_api_name);
        }
    } catch (e) {
        gs.error("Error inserting cmdb_ci_api record: " + e.message);
    }
}
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@keshav77 

to get the current import set you should use import_set object

AnkurBawiskar_0-1752684263795.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar  Do you mean to say use  import_set in on complete transform script. If you saying in workflow I am already using there 

@keshav77 

yes that object is available in oncomplete transform script.

you should send import_set.sys_id to workflow input

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@keshav77 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader