- 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-25-2022 11:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 11:56 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2022 12:08 AM
No, the generated code snippets are unique per Flow, since flows/subflows have different triggers, and inputs and outputs and so on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2022 12:17 AM
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);
}
})();