# Setting Collection variables from scripts

**URL:** <https://community.postman.com/t/setting-collection-variables-from-scripts/9261>\
**Category:** Help Hub\
**Tags:** collections\
**Created:** [November 26, 2019, 8:51pm UTC](https://community.postman.com/t/setting-collection-variables-from-scripts/9261 "2019-11-26T20:51:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![conigbinde](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@conigbinde](https://community.postman.com/u/conigbinde)\
**Post date:** [November 26, 2019, 8:51pm UTC](https://community.postman.com/t/setting-collection-variables-from-scripts/9261/1 "2019-11-26T20:51:32Z")

</div>

Using `pm.collectionVariables.get()` and `pm.collectionVariables.set()`methods in pre-request script or tests to access the collection variables, as described in the product documetation gives a “There was an error in evaluating the Pre-request Script: TypeError: Cannot read property ‘set’ of undefined” error. What is the right way to set the collection variables from a script.

---

<div class="post-metadata">

**Author:** ![amit](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/amit/32/2056_2.png) [@amit](https://community.postman.com/u/amit)\
**Post date:** [November 26, 2019, 8:59pm UTC](https://community.postman.com/t/setting-collection-variables-from-scripts/9261/2 "2019-11-26T20:59:03Z")

</div>

Hey @conigbinde Welcome to the community 👋

`pm.collectionVariables` object was added in Postman version 7.9.0 - Do make sure you are on the latest Postman version to utilize this: [Download Postman | Get Started for Free](https://www.getpostman.com/downloads/)

If you are getting this error on version 7.9.0 or later - let me know which version you are using.
