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

Hello Ankur,

Actually, it needs to check client-side validations.So i am trying to call glideajax.

then you can combine client side + server side code in UI action using gsftSubmit

can you share your complete UI action script and screenshot

Client & Server Code in One UI Action

Regards
Ankur

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

Hello Ankur,

In the UI action, If the Client field is true,  Can we use the server-side script in the script?

yes why not

check this link

Client & Server Code in One UI Action

Regards
Ankur

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

Hello Ankur,

Thanks for suggesting the useful information.

Actually, I am working on the scan task for better performance. One of our scan tasks like "Client-side code should not use GlideRecord". When it comes to UIActions, We are using client-side and server-side code in one UI ACTION, and the client is marked as true. According to the scan task, we should not glide records when the UI action client field is true. Can you please look into the below screenshot for a better understanding?

find_real_file.png

My question is, Is it best practice to write client-side and server-side code in one UI ACTION when the client field is true?