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

The code should be inserted wherever you would invoke the Flow.

I can't say where to put it in your script include, since I'm not sure about what you are doing in that script.

My best guess would be to use it in your function called:
invokeVaccineRequirementFlow: function(requirementGr) {

Hi OlaN,

Thank you for your response, it worked for me!

Regards,
Arpitha G