Using flow templates in Catalog Builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 10:34 AM
Our compliance department will not allow the use of Step Based flows in Catalog Builder. As a result, we created flows as "flow templates" that the citizen developer can select when creating a catalog item in Catalog Builder. However, the current process requires ServiceNow developers to intervene by copying the assigned flow "template" to a new flow to be specific to the catalog item. Any way to automate this by having the flow created from the "template" upon submission of the catalog item in Catalog Builder (maybe a script on the UI Action?), and then update the catalog item with the newly created flow? I have to believe it's possible as virtually anything is possible in ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 11:23 AM
Hi @Aprille ,
Step 1: Clone the Flow Template Programmatically
There’s no out-of-the-box method to "copy a flow", but you can script it by cloning the Flow Designer records (under sys_hub_flow, sys_hub_flow_version, and related sys_hub_action* tables).
ServiceNow does this during export/import, so you can mimic the logic.
Here's a server-side script example (simplified):
function cloneFlowTemplate(templateSysId, targetCatalogItemSysId) {
var originalFlow = new GlideRecord('sys_hub_flow');
if (!originalFlow.get(templateSysId)) {
gs.error('Flow template not found: ' + templateSysId);
return;
}
// Clone the main flow record
var newFlow = new GlideRecord('sys_hub_flow');
newFlow.initialize();
newFlow.name = 'Auto Flow - ' + targetCatalogItemSysId;
newFlow.description = originalFlow.description;
newFlow.application = originalFlow.application;
newFlow.sys_scope = originalFlow.sys_scope;
newFlow.table = originalFlow.table;
newFlow.active = true;
var newFlowSysId = newFlow.insert();
// Clone the flow definition (sys_hub_flow_version)
var version = new GlideRecord('sys_hub_flow_version');
version.addQuery('flow', templateSysId);
version.orderByDesc('sys_created_on');
version.setLimit(1);
version.query();
if (version.next()) {
var clonedVersion = new GlideRecord('sys_hub_flow_version');
clonedVersion.initialize();
clonedVersion.flow = newFlowSysId;
clonedVersion.definition = version.definition; // Optionally deep-copy this if needed
clonedVersion.insert();
}
// Update the catalog item to use the new flow
var item = new GlideRecord('sc_cat_item');
if (item.get(targetCatalogItemSysId)) {
item.flow_designer_flow = newFlowSysId;
item.update();
}
return newFlowSysId;
}
step 2: Trigger This Logic Automatically
You can hook this into the Catalog Builder process using one of the following:
Option A: Business Rule on sc_cat_item
- Trigger on insert or update (when finalized)
- Conditions:
- Template field is set
- No assigned flow yet
- Call the cloneFlowTemplate() logic
Option B: UI Action in Catalog Builder
- Add a "Publish & Attach Flow" UI action
- When clicked, execute the script above
Option C: Flow Designer + Script Action
- If you prefer declarative logic, use a Flow on sc_cat_item insert
- Use a Script Action to run the cloning logic (same logic, just moved to Script Action)
If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.
Regards,
Pratik