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-15-2022 03:06 AM
Hello Ankur,
Actually, it needs to check client-side validations.So i am trying to call glideajax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 03:09 AM
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
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-15-2022 03:14 AM
Hello Ankur,
In the UI action, If the Client field is true, Can we use the server-side script in the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 04:05 AM
yes why not
check this link
Client & Server Code in One UI Action
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 12:04 AM
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?
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?