Happy Business Starts Here

How to invoke a workflow from another workflow?

bharatsingh
Advanced Tutor

How to invoke a workflow from another workflow?

Hi,

I am learning zuora and I have a scenario where I have created two workflows.

WF1

WF2

There I want to invoke WF2 from WF1.

Is it possible? 

12 REPLIES 12
arindamkesh
Valued Scholar

Re: How to invoke a workflow from another workflow?

every workflow has a callout URL (you will find that in settings)

add a callout activity on WF1, and use the URL of WF2 in that

if you want to have security credentials on WF2 and input parameters, you will have to add them on WF2, and configue the WF1 callout accordingly

bhartidalal
Master

Re: How to invoke a workflow from another workflow?

Sure Bharat. That can be done

 

You can achieve this via callout URL. You can directly invoke another workflow from within using the given built-in activity  and configure accordingly

WF.png

msonsma
Valued Scholar

Re: How to invoke a workflow from another workflow?

Keep in mind that when using the Execute::Workflow task the workflow is not portable between tenants!

 

When you export a workflow the generated JSON output will - unfortunately -  refer the called workflow by its internal id. When you import the workflow definition on different tenant,  that id can not be found resulting in an empty Execute::workflow task with all settings lost. You have to manually select the correct workflow and setup all parameters again 😞

 

A better and portable approach is to use two tasks:

1) A notification::callout task to lookup the target workflow by it's name ( see REST API GetWorkflows ) 

2) A notification::callout task to execute the target workflow by its id ( see REST API RunWorkflow  ) with the body set to the parameters  (form encoded).

 

In this way you can deploy your set of workflows on any tenant without manual updates.

 

BR

Manfred

 

 

Ridhima
Valued Scholar

Re: How to invoke a workflow from another workflow?

Thank you for your response msonsma. Do you also have callouts which call workflows by id? Any ideas how we can automate that?

msonsma
Valued Scholar

Re: How to invoke a workflow from another workflow?


@Ridhima wrote:

Thank you for your response msonsma. Do you also have callouts which call workflows by id? Any ideas how we can automate that?


Hi

 

Not sure whether I understand your question.

 

Do you mean an example of how to set it up in a workflow using the workflow's notification::callout task or how to start a workflow by a Zuora predefined or custom event trigger ( Zuora ->Settings->Billing/Payments->Setup Profiles, Notifications and Email Templates).

 

Manfred

SubscriptionFactory.com

gauri
Master

Re: How to invoke a workflow from another workflow?

@Ridhima - Take a look at these API calls available for workflows - https://www.zuora.com/developer/api-reference/#tag/Workflows

 

This will help with automation you are looking into. 

 

 

Tags (2)
msonsma
Valued Scholar

Re: How to invoke a workflow from another workflow?

@gauri  Yeah and that reference to the REST API is different from the ones in my post ? 

Ridhima
Valued Scholar

Re: How to invoke a workflow from another workflow?

I was asking -  how to start a workflow by a Zuora predefined or custom event trigger ( Zuora ->Settings->Billing/Payments->Setup Profiles, Notifications and Email Templates).

We have used only ids to configure callout to workflow here. But If I import workflow, then everytime id changes. We do not want to configure and change ids in callout again and again. How do we handle this?

msonsma
Valued Scholar

Re: How to invoke a workflow from another workflow?

Hi @Ridhima 

 

You just hit one of the most annoying things with Zuora workflows: deploying and versioning of workflows. 

 

Zuora should implement some kind of versioning scheme for workflows and offer an option to reference a workflow by its (abbrev) name and version level required. 

 

For instance: 

https://workflow.apps.zuora.com/api/v1/workflows/MYWORKFLOW/run?version=latest

 

If you than roll out a new version, that new version will automatically be used by the call-out unless the callout is tight to a specific version.

 

Ok, but let's not wait until hell freezes over....

 

What you can do to use a "man in the middle" approach. Rather than calling the workflow directly, use an intermediate (sync) workflow that will start the correct version of the workflow and pass the parameters to that workflow. This intermediate workflow will use the approach describe earlier to find a workflow by its name and use the returned workflow id to execute that  workflow. You can use liquid or a bit of JSONata to pass through the  parameters to the workflow you want to call.

 

You can also code the "man in middle" workflow as a generic dispatcher by passing the name/version of the workflow you want to start as parameters in the notification callout.

 

With this man in the middle workflow you can deploy new versions of your workflow without updating the callouts....

 

BR

Manfred

SubscriptionFactory.com