Use one condition with multiple flow steps

In the Preflow I have several steps that should run only if a condition is fulfilled.

Is there a way to set the same condition to a group of steps, instead of setting the condition for each step and duplicating the code?

You can use shared flow and put the shared flow with condition.

1 Like

Thanks. I am familiar with this option. But shared flows are supposed to be shared between proxies.

In this case, the flow segment is part of only one proxy, and I would not like to develop one proxy in two places.

Then you can put a conditional flow, and add all the policies to that. This will execute only when your condition is true. Note, if you have another conditional flow, then don’t use this option.

1 Like

Yes, here’s an example.

But this is not in the PreFlow, Kurt?

No, not in the preflow. This is not possible:

<PreFlow name='preflow'>
  <Request>
    <Series> <!-- this is not valid -->
      <Step><Name>Step-1</Name></Step>
      <Step><Name>Step-1</Name></Step>
      <Step><Name>Step-1</Name></Step>
      <Step><Name>Step-1</Name></Step>
      <Condition> flow.variable = "yes"</Condition>
    </Series>
  </Request>
</PreFlow>
  

There is no way to wrap a condition around multiple steps in the preflow without repeating the condition. This way:

<PreFlow name='preflow'>
  <Request>
    <Step>
      <Name>Step-1</Name>
      <Condition> flow.variable = "yes"</Condition>
    </Step>
    <Step>
      <Name>Step-1</Name>
      <Condition> flow.variable = "yes"</Condition>
    </Step>
    <Step>
      <Name>Step-1</Name>
      <Condition> flow.variable = "yes"</Condition>
    </Step>
    <Step>
      <Name>Step-1</Name>
      <Condition> flow.variable = "yes"</Condition>
    </Step>
  </Request>
</PreFlow>

Wrapping the series of steps into a sharedflow works, as Priyadarshi pointed out. But if you don’t want to “share” the series of steps outside the proxy, then… not.

This is a limitation of the Apigee DSL.

Right, my bad, this looks good but will only execute one conditional flow.