# Using if statement for workflow

**URL:** <https://community.postman.com/t/using-if-statement-for-workflow/27802>\
**Category:** Help Hub\
**Created:** [September 13, 2021, 7:57pm UTC](https://community.postman.com/t/using-if-statement-for-workflow/27802 "2021-09-13T19:57:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hannahbroch](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@hannahbroch](https://community.postman.com/u/hannahbroch)\
**Post date:** [September 13, 2021, 7:57pm UTC](https://community.postman.com/t/using-if-statement-for-workflow/27802/1 "2021-09-13T19:57:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 13, 2021, 8:12pm UTC](https://community.postman.com/t/using-if-statement-for-workflow/27802/2 "2021-09-13T20:12:34Z")

</div>

Hey,

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

To _get_ globals you would use

```auto
pm.globals.get('var_name');

```

To _set_ globals you would use

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

```

---

<div class="post-metadata">

**Author:** ![hannahbroch](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@hannahbroch](https://community.postman.com/u/hannahbroch)\
**Post date:** [September 14, 2021, 6:28am UTC](https://community.postman.com/t/using-if-statement-for-workflow/27802/3 "2021-09-14T06:28:42Z")

</div>

i was trying to set the order of the collection run

---

<div class="post-metadata">

**Author:** ![sean.keegan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sean.keegan/32/6353_2.png) [@sean.keegan](https://community.postman.com/u/sean.keegan)\
**Post date:** [September 15, 2021, 4:53pm UTC](https://community.postman.com/t/using-if-statement-for-workflow/27802/4 "2021-09-15T16:53:41Z")

</div>

Hi @hannahbroch!

It seems like you’re close to the functionality you want, but like @danny-dainton 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](https://learning.postman.com/docs/running-collections/building-workflows/) 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!

---

<div class="post-metadata">

**Author:** ![hannahbroch](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@hannahbroch](https://community.postman.com/u/hannahbroch)\
**Post date:** [September 29, 2021, 7:17pm UTC](https://community.postman.com/t/using-if-statement-for-workflow/27802/5 "2021-09-29T19:17:26Z")

</div>

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?
