# Newman cant update new values to postman environment variables

**URL:** <https://community.postman.com/t/newman-cant-update-new-values-to-postman-environment-variables/34439>\
**Category:** Help Hub\
**Tags:** newman-project, tests, variables, ci-cd, collections\
**Created:** [April 12, 2022, 1:48pm UTC](https://community.postman.com/t/newman-cant-update-new-values-to-postman-environment-variables/34439 "2022-04-12T13:48:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciapas.laurynas](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@ciapas.laurynas](https://community.postman.com/u/ciapas.laurynas)\
**Post date:** [April 12, 2022, 1:48pm UTC](https://community.postman.com/t/newman-cant-update-new-values-to-postman-environment-variables/34439/1 "2022-04-12T13:48:46Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

Hello,  
Im calling postman collection LOCALLY through newman and it cant update new values for environment variables. My code is below:

```auto
var sum = 250;
var totalPaidAmount = Number(pm.collectionVariables.get("ContractPaidAmount"));
var sumOfContractTotalPaidAmount = totalPaidAmount + sum;
pm.environment.set("ContractPaidAmount",sumOfContractTotalPaidAmount);
pm.collectionVariables.set("ContractPaidAmount",sumOfContractTotalPaidAmount);

```

whether it is possible at all to do these things in newman?  
Already integrated postman tests through newman in Azure CI/CD and thought that impossible to newman modify file values without my manual interaction…

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/4/4e93c5539dad80d2e85a90cec04608bfcb681327.png)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [April 12, 2022, 5:41pm UTC](https://community.postman.com/t/newman-cant-update-new-values-to-postman-environment-variables/34439/2 "2022-04-12T17:41:45Z")

</div>

Hi @ciapas.laurynas

Using the same logic you shared above, I ran the following test collection in Newman with a pre-req script that updated my environment’s file and it appears to work.

Here is what I did;

Generated a random number between 1 and 36 and used the environment.set to save the variable.  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/4/44313865b015f79d1692d4ef4ba5dbb42126bd48.png)

Then set the variable where I needed the random number to be fed in.  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/c/c5bc955d70948841154fb2b5bced204285c40628.png)

Then ran it in Newman, with the -e option for including my environments file. It ran for 5 iterations and as you can see the page number changes for each.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/a/a21c4f61aea523632e3b9047fba48f63ecbbfc37.png)

* * *

When you run your code with logging, you get NaN (not a number)

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/7/7748b9e0114d5dcc20ae8c815fc9bc0b8fc477f8.png)

This is because your second line is equal to “Number(A NUMBER)” … which is not a number. I suspect this line should be;

`var totalPaidAmount = pm.collectionVariables.get("ContractPaidAmount");`

---

<div class="post-metadata">

**Author:** ![ciapas.laurynas](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@ciapas.laurynas](https://community.postman.com/u/ciapas.laurynas)\
**Post date:** [April 13, 2022, 10:15am UTC](https://community.postman.com/t/newman-cant-update-new-values-to-postman-environment-variables/34439/3 "2022-04-13T10:15:08Z")

</div>

Hello,  
thanks for the advice, I have fixed it. It works only in the current session, current environment variable values updates in the current session. Example:

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/3/31ab244e14ac06ef4ddd6bfc585b68ade2ca426d.png)  
But if i run tests in another time, all variables has last EXPORTED collection values and it loads i guess initial environment variables values. How can i update initial environment values? My variables should keep information from the last run.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [April 13, 2022, 10:26am UTC](https://community.postman.com/t/newman-cant-update-new-values-to-postman-environment-variables/34439/4 "2022-04-13T10:26:08Z")

</div>

> [@ciapas.laurynas](#):
>
> How can I update initial environment values? My variables should keep information from the last run.

Try looking into the --export-environment option;

> –export-collection   
> The path to the file where Newman will output the final collection file before completing a run.

Newman options can be found here;

> **[newman](https://www.npmjs.com/package/newman#using-newman-cli)**
>
> Command-line companion utility for Postman. Latest version: 6.0.0, last published: 2 months ago. Start using newman in your project by running \`npm i newman\`. There are 181 other projects in the npm registry using newman.

---

<div class="post-metadata">

**Author:** ![ciapas.laurynas](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@ciapas.laurynas](https://community.postman.com/u/ciapas.laurynas)\
**Post date:** [April 13, 2022, 11:54am UTC](https://community.postman.com/t/newman-cant-update-new-values-to-postman-environment-variables/34439/5 "2022-04-13T11:54:54Z")

</div>

Thanks,  
locally it works!
