# User-defined script library

**URL:** <https://community.postman.com/t/user-defined-script-library/6731>\
**Category:** Help Hub\
**Tags:** tests, scripts, library\
**Created:** [July 24, 2019, 8:13am UTC](https://community.postman.com/t/user-defined-script-library/6731 "2019-07-24T08:13:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krushinatorx](https://avatars.discourse-cdn.com/v4/letter/k/5e9695/32.png) [@krushinatorx](https://community.postman.com/u/krushinatorx)\
**Post date:** [July 24, 2019, 8:13am UTC](https://community.postman.com/t/user-defined-script-library/6731/1 "2019-07-24T08:13:35Z")

</div>

Hi!

I have some scripts that I have written myself that perform parsing and assertions on responses and I reuse these in multiple requests. Currently I am copying and pasting each of these scripts into each test. It would be nice to have the functions declared in a central library so I don’t have to manually update each collection/folder/request where they are declared.

I figured that maybe declaring a function on the collection level would make it available for a request within that folder, but no such luck. From the Postman Console:

```
ReferenceError | parseResponse is not defined

```

Is it possible to reference in a user-defined collection of functions?

-KX

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [July 30, 2019, 12:32pm UTC](https://community.postman.com/t/user-defined-script-library/6731/2 "2019-07-30T12:32:23Z")

</div>

This is a really good idea. You should submit a feature request on [GitHub](https://github.com/postmanlabs/postman-app-support/issues)

---

<div class="post-metadata">

**Author:** ![krushinatorx](https://avatars.discourse-cdn.com/v4/letter/k/5e9695/32.png) [@krushinatorx](https://community.postman.com/u/krushinatorx)\
**Post date:** [August 20, 2019, 7:39am UTC](https://community.postman.com/t/user-defined-script-library/6731/3 "2019-08-20T07:39:54Z")

</div>

So not currently supported, then 🙂

-KX

---

<div class="post-metadata">

**Author:** ![emmaDF](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@emmaDF](https://community.postman.com/u/emmaDF)\
**Post date:** [August 22, 2019, 10:43am UTC](https://community.postman.com/t/user-defined-script-library/6731/4 "2019-08-22T10:43:18Z")

</div>

I do this by running something in the test script for the collection that defines a global variable, then I can reuse in my tests.  
In the collection scripts:

postman.setGlobalVariable(“DoAThing”, (Variable) =\> {  
//do some stuff  
});

And then in the specific tests as:  
eval(globals.DoAThing)(var);

It’s not great, and eval isn’t a great thing to use, but it saved me a lot of time compared to changing stuff directly in loads of individual tests!

---

<div class="post-metadata">

**Author:** ![aamir.ahmed](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@aamir.ahmed](https://community.postman.com/u/aamir.ahmed)\
**Post date:** [August 23, 2019, 5:55am UTC](https://community.postman.com/t/user-defined-script-library/6731/5 "2019-08-23T05:55:52Z")

</div>

Hi @emmaDF,

You can execute the same tests for every request in the collection without specifically adding it to each request by adding the tests at the collection level.  
You can write test scripts at the collection level by clicking on the ellipsis “…” next to the collection, clicking on Edit and adding your test scripts in your pre-request scripts or tests based on your requirements as seen in the attached image.

 ![collectionleveltests](https://us1.discourse-cdn.com/getpostman/original/2X/b/b94f2bd19089e933e09a8dec4de3cd0affa7c69e.png)
