# Global functions at the Collection level

**URL:** <https://community.postman.com/t/global-functions-at-the-collection-level/10722>\
**Category:** Help Hub\
**Tags:** collections\
**Created:** [February 11, 2020, 8:34am UTC](https://community.postman.com/t/global-functions-at-the-collection-level/10722 "2020-02-11T08:34:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yael](https://avatars.discourse-cdn.com/v4/letter/y/f6c823/32.png) [@yael](https://community.postman.com/u/yael)\
**Post date:** [February 11, 2020, 8:34am UTC](https://community.postman.com/t/global-functions-at-the-collection-level/10722/1 "2020-02-11T08:34:01Z")

</div>

How can I use global function (which receives parameters) in the Collection level (either in the Pre-Request or Tests section) and afterwards call the function from the request?  
I tried implementing it, and it failed. Got error that the function is not defined.

---

<div class="post-metadata">

**Author:** ![migmaqer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/migmaqer/32/4858_2.png) [@migmaqer](https://community.postman.com/u/migmaqer)\
**Post date:** [February 21, 2022, 4:57pm UTC](https://community.postman.com/t/global-functions-at-the-collection-level/10722/2 "2022-02-21T16:57:57Z")

</div>

old school solution:

…in collection pre-req:  
postman.setGlobalVariable(“foo2Function”, () =\> {

```
// do your stuff here

```

});

…in test:  
foo2 = eval(pm.globals.get(“foo2Function”));

foo2();

---

<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:** [December 12, 2024, 12:55pm UTC](https://community.postman.com/t/global-functions-at-the-collection-level/10722/3 "2024-12-12T12:55:15Z")

</div>

Closed on December 12, 2024, 12:55pm UTC

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