Trigger design flow using UI action button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 08:52 PM
Hi All,
Trying to trigger design flow using UI action button (button exist in sc_Task form), once we click on button design flow should trigger.
Button name : Create Jira story
UI action script:
(function() {
try {
var rec_id = current.sys_id;
var gr = new GlideRecord('sc_task');
if (gr.get(rec_id)) {
var inputs = {};
inputs['current'] = current; // GlideRecord of table:
inputs['table_name'] = 'sc_task';
sn_fd.FlowAPI.executeFlow('Flow name', inputs);
}
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
Do we need to set any condition in design flow or how we can link UI action script to run flow, without condition we cannot trigger the flow.
Action : Create story in jira.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 09:36 PM
Hi,
why to use UI action to trigger flow?
You can configure flow condition accordingly based on some update it triggers
Did you configure the flow on sc_task and published it? share screenshot for that
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
01-26-2022 09:36 PM
Hi,
You can call a flow designer from a UI Action. Please follow the below steps/ code to call a flow:
1. Navigate to any 'Flow Designer' module under Automations. Open the flow which you want to trigger on clicking of UI Action button.
2. On the extreme right, click on 'More actions menu' and click on Code Snippet. You can use the code in the Code Snippet to in include it in the UI Action.
Sample of the code from the Code Snippet:
var flowInputs = {};
flowInputs['current'] = current;
flowInputs['table_name'] = current.getTableName();
var result = sn_fd.Flow.startAsync('SCOPENAME.FLOWNAME', flowInputs);
//The Sys ID of a flow execution (contextId)
var contextId = result.contextId;
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
Regards,
Ankita Sarkar