How to call workflow from script include

Rama Rao
Tera Contributor

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());

}
},

24 REPLIES 24

I believe I have provided enough help on your questions.

The script I shared will work fine provided you debug and find the issue such as is script include client callable, any error in script by adding logs etc

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Rama Rao 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Rama Rao 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Not required query the "wf_context" table?

 

Prasad Pagar
Mega Sage

Hi,

One more basic, 'current' object doesn't work in Client script so I presume your client script is not even calling script include.

Thank you
Prasad