# Global name 'self' is not defined in script

**URL:** <https://forum.inductiveautomation.com/t/global-name-self-is-not-defined-in-script/69778>\
**Category:** Ignition\
**Created:** [February 13, 2023, 4:14pm UTC](https://forum.inductiveautomation.com/t/global-name-self-is-not-defined-in-script/69778 "2023-02-13T16:14:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sagar.iparkar](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sagar.iparkar](https://forum.inductiveautomation.com/u/sagar.iparkar)\
**Post date:** [February 13, 2023, 4:14pm UTC](https://forum.inductiveautomation.com/t/global-name-self-is-not-defined-in-script/69778/1 "2023-02-13T16:14:10Z")

</div>

userName= getattr(self.session.custom, "userName")  
global name 'self' is not defined showing error

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 13, 2023, 4:19pm UTC](https://forum.inductiveautomation.com/t/global-name-self-is-not-defined-in-script/69778/2 "2023-02-13T16:19:23Z")

</div>

This is not enough information to offer particularly useful troubleshooting advice.

Where is this script written? What arguments are you passing in, if it's a defined function? Where is it being called from?

---

<div class="post-metadata">

**Author:** ![sagar.iparkar](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sagar.iparkar](https://forum.inductiveautomation.com/u/sagar.iparkar)\
**Post date:** [February 14, 2023, 2:51am UTC](https://forum.inductiveautomation.com/t/global-name-self-is-not-defined-in-script/69778/3 "2023-02-14T02:51:16Z")

</div>

below Script define in project library .

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4cdca213320723056ac66b92bdba1b04e52a2988.png)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [February 14, 2023, 4:25am UTC](https://forum.inductiveautomation.com/t/global-name-self-is-not-defined-in-script/69778/4 "2023-02-14T04:25:37Z")

</div>

self is not defined in your script. Change your function to `def getRecord(self):`, and then pass your source into the function when you call it.
