Using if statement for workflow

I was attempting to use an if statement to create a workflow. I wanted the collection to run in the chronological way except when this statement is true.
I used
if (postman.globals.get(“runnedOnce”)) {
postman.setNextRequest(“view enterprise’s payee settings after statementEmail is provided”);

}

postman.globals.set(“runnedOnce”, 1);

However im getting an error TypeError: Cannot read property ‘get’ of undefined

please help

Hey,

Not sure where you have found that syntax but it’s not quite right. :thinking:

To get globals you would use

pm.globals.get('var_name');

To set globals you would use

pm.globals.set('var_name', 'var_value');

i was trying to set the order of the collection run

Hi @hannahbroch!

It seems like you’re close to the functionality you want, but like @dannydainton mentioned above, your syntax for getting the global variable is slightly off, which will result in the “TypeError: Cannot read property ‘get’ of undefined” error you’re seeing. Have you run into this error while using Danny’s syntax suggestions? It’s also worth noting that if you set runnedOnce after you run the if statement, the if statement will not evaluate to true and you’ll never hit that block of code.

You’re using the right method to set the next request. If you want more information on building workflows in Postman, this section of our documentation may be helpful.

Another option would be putting your request in a public workspace so that folks can go see the full code and help out with more context.

Hope that helps!

2 Likes

thanks
Im not sure if i made my question clear. Im looking to see how if i run a workflow according the to correct order until it gets to request number 5 and then to jump it back to request number 2 and then only if it goes to request number 2 the 2nd time to jump it to request number 6, how would i go about this?