# Conditionally update one field based on the value of another

**URL:** <https://community.postman.com/t/conditionally-update-one-field-based-on-the-value-of-another/57155>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [February 1, 2024, 12:13am UTC](https://community.postman.com/t/conditionally-update-one-field-based-on-the-value-of-another/57155 "2024-02-01T00:13:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![keith1990](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@keith1990](https://community.postman.com/u/keith1990)\
**Post date:** [February 1, 2024, 12:13am UTC](https://community.postman.com/t/conditionally-update-one-field-based-on-the-value-of-another/57155/1 "2024-02-01T00:13:22Z")

</div>

I have a request to use existing REST APIs to update a field based on the value of another field. E.G.  
If “Status” = “High” Set “Priority” = '1"  
Else If "Status = “Normal” Set Priority = 2  
Else Set “Priority” = “3”

Can this be done in one Patch operation using query parms/varibales?  
Or would it be better to somehow use results of a “GET” to feed multiple "PATCH"s?

Hope this makes sense?

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [February 1, 2024, 9:27am UTC](https://community.postman.com/t/conditionally-update-one-field-based-on-the-value-of-another/57155/2 "2024-02-01T09:27:29Z")

</div>

Hi @keith1990. Welcome to the Postman Community.

Postman allows you to build a workflow with different requests in a collection. The most straightforward way is to do this using two different requests.

After the first request, you can store the needed value in an [environment or collection variable](https://learning.postman.com/docs/collections/running-collections/building-workflows/) using [Postman Scripts](https://learning.postman.com/docs/writing-scripts/intro-to-scripts/) in the scripting tab.

These variables can be used in the request body, query or path parameters of your next request.

Ensure you run your requests using the collection runner so that they run sequentially immediately after one another.

---

<div class="post-metadata">

**Author:** ![keith1990](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@keith1990](https://community.postman.com/u/keith1990)\
**Post date:** [February 2, 2024, 1:57am UTC](https://community.postman.com/t/conditionally-update-one-field-based-on-the-value-of-another/57155/3 "2024-02-02T01:57:45Z")

</div>

Thank you so much @gbadebo-bello - You got me off to a great start. Still lots to learn but I got this conditional update working using collection variables.

This following thread was very helpful too, if anyone else is in my situation:

> [@How to store a JSON in a variable and use it in the request body?](https://community.postman.com/t/how-to-store-a-json-in-a-variable-and-use-it-in-the-request-body/1881):
>
> Hi, I want to run a collection with specific test data, but restore the data from before my collection run afterwards. My idea to achieve this is so far: Execute a GET request to retrieve the currently available data. Format: JSON Store that data in an environmentvariable Run collection that includes overriding the original data with PUT request containing my test data. Restore the original data from the environmentvariable However this doesn’t seem to work. Approach #1: I used the code f…

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [February 2, 2024, 12:33pm UTC](https://community.postman.com/t/conditionally-update-one-field-based-on-the-value-of-another/57155/4 "2024-02-02T12:33:05Z")

</div>

Happy to hear that, @keith1990!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 3, 2024, 12:33pm UTC](https://community.postman.com/t/conditionally-update-one-field-based-on-the-value-of-another/57155/5 "2024-03-03T12:33:27Z")

</div>

Closed on March 3, 2024, 12:33pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
