Calling a flow from the Workspace UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
Hi @ext_amritad
Before calling the subflow in client side please follow the below article as reference, i hope it will work for you.
https://www.servicenow.com/docs/r/zurich/build-workflows/workflow-studio/grant-access-flow-apis.html
By default, the flows, subflows, and actions can only be called by the FlowAPI within a server script. Flow and action designers can make individual flows, subflows, or actions available to client calls by enabling the Client callable option during the design process.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @ext_amritad,
In Workspace you cannot use "current" or "action.setRedirectURL()", so the server part has to move into a client callable Script Include and you call it from the Workspace Client Script using GlideAjax.
Script Include (tick Client callable):
var TeamsMeetingAjax = Class.create();
TeamsMeetingAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
createMeeting: function() {
try {
var inputs = {};
inputs['incident'] = this.getParameter('sysparm_incident_id');
sn_fd.FlowAPI.getRunner()
.subflow('global.create_teams_meeting_on_demand_p2')
.inForeground()
.withInputs(inputs)
.run();
return 'success';
} catch (ex) {
gs.error(ex.getMessage());
return ex.getMessage();
}
},
type: 'TeamsMeetingAjax'
});
On the UI Action tick Workspace Form Button, then in the Workspace Client Script field:
function onClick(g_form) {
var ga = new GlideAjax('TeamsMeetingAjax');
ga.addParam('sysparm_name', 'createMeeting');
ga.addParam('sysparm_incident_id', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer) {
if (answer == 'success') {
g_form.addInfoMessage('Teams meeting created');
g_form.reload();
} else {
g_form.addErrorMessage(answer);
}
});
}
Two things to check in your original script. The gs.info("line 10" + result) line runs before result is set, so it will always log undefined. Also, if the subflow takes a few seconds to create the meeting, use .inBackground() instead so the user is not stuck waiting, as long as you do not need outputs.
You can keep the existing server script on the same UI Action. Classic UI will use that and Workspace will use the client script, and both call the same subflow.
If this answer helped you, please mark it as Helpful and Accept as Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
workspace client script supports only client side logic and your logic is server side
you can use GlideAjax and call that function from workspace client script
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
