What parameters should be used to initiate the Flow designer in Script include?

Arpitha Gopalsw
Giga Guru

I have added the below functions in script include to initiate the flow designer from Script include. Kindly advice if the below code is correct or any corrections needed. When added the logs, it throwing errors at many places. Please help me fix it as, I'm new for scripting.

Script include: xyzutils

getVaccineProfileByCoreUser: function(userid) {
gs.info("Arpitha1");
if (userid) {
var coreGr = new GlideRecord('sn_imt_vaccine_vaccine_profile');
coreGr.addQuery('user', userid);
coreGr.query();
if (coreGr.next()) {
return this.getEmployeeRequirements(coreGr.core_user.sys_id);
}
}
},

getEmployeeRequirements: function(coreUserid) {

var employeeReqGr = new GlideRecord('sn_imt_core_employee_health_and_safety_requirement');
employeeReqGr.addQuery('health_and_safety_user', coreUserid);
employeeReqGr.query();
while (employeeReqGr.next()) {
var reqFlow = employeeReqGr.health_and_safety_requirement.getRefRecord();
this.invokeVaccineRequirementFlow(reqFlow);
gs.info(reqFlow + "Arpitha2");
}
},

invokeVaccineRequirementFlow: function(requirementGr) {

sn_fd.FlowAPI.startFlow(
this._getFlowName(requirementGr.getValue('requirement_flow')), {
}
);
gs.info(requirement_flow + "Arpitha3");
},

_getFlowName: function(flowId) {
var flowGr = new GlideRecord('sys_hub_flow');
if (!flowGr.get(flowId)) {
throw new Error("Flow '" + flowId + "' not found");
}
if (flowGr.getValue('type') !== 'flow') {
throw new Error("Flow '" + flowId + "' is of type " + flowGr.getValue('type'));
}

return flowGr.getElement('sys_scope.scope') + '.' + flowGr.getValue('internal_name');
},

Logs screenshot attached below:

find_real_file.png

Thanks in Advance!

Regards,
Arpitha G

1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

Hi,

Open the Flow in Flow designer, and use the create code snippet, to generate code to call from script include.

find_real_file.png

View solution in original post

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

Open the Flow in Flow designer, and use the create code snippet, to generate code to call from script include.

find_real_file.png

Hi OlaN,

Based on the requirement flow in the "sn_imt_core_employee_health_and_safety_requirement" table, the flow designer should be initiated. Does this code snippet to be used in all the requirements flow as it a reference field from sys_hub_flow table?

Regards,

Arpitha G

No, the generated code snippets are unique per Flow, since flows/subflows have different triggers, and inputs and outputs and so on.

Thanks for the update. Could you let me know where exactly that code snippet should be used in the above code? I'm new to scripting. 

Kindly help!

 

Below is the snippet i found:

(function() {

try {
var inputs = {};
inputs['current'] = ; // GlideRecord of table:
inputs['changed_fields'] = ; // Array.Object
inputs['table_name'] = 'sn_imt_vaccine_vaccine_profile';

// Start Asynchronously: Uncomment to run in background.
// sn_fd.FlowAPI.getRunner().flow('sn_imt_core.mars_covid19_vaccination_requirement').inBackground().withInputs(inputs).run();

// Execute Synchronously: Run in foreground.
sn_fd.FlowAPI.getRunner().flow('sn_imt_core.mars_covid19_vaccination_requirement').inForeground().withInputs(inputs).run();

} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}

})();

(function() {

try {
var inputs = {};
inputs['current'] = ; // GlideRecord of table:
inputs['changed_fields'] = ; // Array.Object
inputs['table_name'] = 'sn_imt_vaccine_vaccine_profile';

// Start Asynchronously: Uncomment to run in background.
// sn_fd.FlowAPI.getRunner().flow('sn_imt_core.mars__us__covid19_vaccine_requirement').inBackground().withInputs(inputs).run();

// Execute Synchronously: Run in foreground.
sn_fd.FlowAPI.getRunner().flow('sn_imt_core.mars__us__covid19_vaccine_requirement').inForeground().withInputs(inputs).run();

} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}

})();