How to call workflow from script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 01:45 AM
Hello,
I need to call the workflow from client-side code using script include. I have tried with the below code but it did not work.
Can anyone please help me to solve this issue? I am unable to call the workflow through this code.
Clientside code :
function setRedirect() {
current.u_next_state = '4';
var workflow = new GlideAjax("YaraNSSRWorkflowUtil");
workflow.addParam("sysparm_name", "getDesignWorkflow");
workflow.addParam("sysparm_profile", g_form.getUniqueValue());
workflow.getXMLAnswer(function(answer) {
answer;
});
}
Script Include Code:
getDesignWorkflow: function() {
var w = new Workflow();
var name = this.getParameter("sysparm_profile");
var wfContext = new GlideRecord('wf_context');
wfContext.addQuery('sys_id', name);
wfContext.addQuery('workflow_version.name', "Yara_NSSR_Before_Design_Approvals");
wfContext.query();
if (!wfContext.next()) {
var wf = new GlideRecord("wf_workflow");
if (wf.get("name", "Yara_NSSR_Before_Design_Approvals"))
return w.startFlow(wf.sys_id, current, current.operation());
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 03:30 AM
Hello Ankur,
I need only client-side because I have enabled the client field in UI action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 03:41 AM
then use GlideAjax
function setRedirect() {
var workflow = new GlideAjax("YaraNSSRWorkflowUtil");
workflow.addParam("sysparm_name", "getDesignWorkflow");
workflow.addParam("sysparm_sysId", g_form.getUniqueValue());
workflow.addParam("sysparm_tableName", g_form.getTableName());
workflow.getXMLAnswer(function(answer) {
});
}
Script Include:
getDesignWorkflow: function() {
var sysId = this.getParameter('sysparm_sysId');
var table = this.getParameter('sysparm_tableName')
var wfContext = new GlideRecord('wf_context');
wfContext.addQuery('id', sysId);
wfContext.addQuery('workflow_version.name', "Yara_NSSR_Before_Design_Approvals");
wfContext.query();
if (!wfContext.next()) {
var rec = new GlideRecord(table);
rec.get(sysId);
var wf = new GlideRecord("wf_workflow");
wf.startFlow(wf1.getWorkflowFromName('Yara_NSSR_Before_Design_Approvals'), rec, 'update');
}
},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 10:03 PM
Hello Ankur,
Tried with the above code but still, it's not triggering workflow. Need more help to sove this?
Can we call the script include in workflow instead of ui action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 10:17 PM
Hi,
you want to call workflow from Script include using GlideAjax
So the above code I shared would work fine
what debugging have you performed?
Did you check the table and sysId came fine in script include?
did it go inside the if condition?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 12:28 AM
Hello Ankur,
Logs and alerts are not triggering. I think the code not working. Can you please look into it once?