Service Portal: Error invoking getResultsFromScratchpad() during input processing

Sreekarr Yallap
ServiceNow Employee
ServiceNow Employee

Hello,

I have a method named getResultsfromScratchpad() that returns an object. I call this method in my server script in two scenarios:

  1. When the initial data is loaded from the server.
  2. When processing user input.

Step 1:

if (!input) {
     var wfscratchpad = '';
     var wfGr = new GlideRecord('wf_context');
     if (wfGr.get(preflightWfSysId)) {
            wfscratchpad = wfGr.scratchpad;
	    data.preflightCreatedDateTime = String(wfGr.started);
            var pgmgResult = getResultsFromScratchpad(wfscratchpad);
	    data.state = pgmgResult.automationState;
	    data.validationTestResults = pgmgResult.validationTestResults;
	   data.pgMigrationPreflightResultCount = pgmgResult.count;
        }
}


Step 2: 
Issue : When I try to call getResultsfromScratchpad(), the control goes to the catch block. In other words, I am unable to call getResultsfromScratchpad() here. Could this be related to a scope issue?

if(input){
		var inputs = {
            u_instance_sys_id: input.instanceSysId,
            u_profile_name: 'pg.runtime.profile',
            u_pg_migration_request_sys_id: '',
            u_pg_migration_context_sys_id: input.pgMigrationSysId
        };

        var wfContextSysId = '';
        try {
            var result = CidSimpleWorkflowHelper.launchWorkflow("PGValidationWF", inputs);
            if (!gs.nil(result)) {
                wfContextSysId = result.wfContextSysId;
                wfContextOutput = result.waitForWorkflowOutput(2000, 90);
                data.preflightOutput = getResultsFromScratchpad(wfContextOutput);
            }
        } catch (e) {
            data.showErrorMsg = true;
            data.errorMsg = "Failed to run  workflow.";
            data.errorMsg += !gs.nil(wfContextSysId) ? "The wf with sys_id '" + wfContextSysId + "' has been triggered" : "";
        }

		
	}


Server script : 

(function() {
 /*Step 1: Load initial data from server*/ 
 if(!input){
   .. 
    var pgmgResult = getResultsFromScratchpad(wfscratchpad);
  ..
  }

/*Step 2: Processing user input */
if(input){
 ..
 data.preflightOutput = getResultsFromScratchpad(wfContextOutput);

}

function getResultsFromScratcpad(){
 ....
 return resultObj;
}

})();
0 REPLIES 0