- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 11:42 PM
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:
Thanks in Advance!
Regards,
Arpitha G
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 11:50 PM
Hi,
Open the Flow in Flow designer, and use the create code snippet, to generate code to call from script include.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2022 01:01 AM
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) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2022 05:38 AM
Hi OlaN,
Thank you for your response, it worked for me!
Regards,
Arpitha G