# Calling function from scripting fails on first load

**URL:** <https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 18, 2025, 7:29am UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745 "2025-09-18T07:29:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmadariaga](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmadariaga/32/63201_2.png) [@mmadariaga](https://forum.inductiveautomation.com/u/mmadariaga)\
**Post date:** [September 18, 2025, 7:29am UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/1 "2025-09-18T07:29:11Z")

</div>

I'm using a custom function from my Scripting on a binding. When it runs for the first time, the import fails, but if I force the binding again it works.

![image](https://us1.discourse-cdn.com/inductiveautomation/optimized/3X/8/6/8658f40c26a35a95e5fd3b9883167763b42aadbe_2_690x18.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/374a539aefead30579373d674084f4d0bc775df1.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 18, 2025, 11:26am UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/2 "2025-09-18T11:26:38Z")

</div>

If you are trying to import your project library scripts, don't they are auto imported for you and should be referenced by their fully qualified name.

---

<div class="post-metadata">

**Author:** ![mmadariaga](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmadariaga/32/63201_2.png) [@mmadariaga](https://forum.inductiveautomation.com/u/mmadariaga)\
**Post date:** [September 18, 2025, 12:17pm UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/3 "2025-09-18T12:17:40Z")

</div>

I'm not importing them:

```python
def transform(self, value, quality, timestamp):
    costs = scripts.opportunities.review.costs.calculate_review_costs(value)
    return costs

```

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 18, 2025, 1:57pm UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/4 "2025-09-18T13:57:45Z")

</div>

Is there an import on line 1 of `scripts.opportunities.review.costs`?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 18, 2025, 2:06pm UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/5 "2025-09-18T14:06:28Z")

</div>

Is the binding NULL to start? Is it a query binding or similar that takes a second to get a value? What is the binding you are doing the transform on.

---

<div class="post-metadata">

**Author:** ![mmadariaga](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmadariaga/32/63201_2.png) [@mmadariaga](https://forum.inductiveautomation.com/u/mmadariaga)\
**Post date:** [September 18, 2025, 2:11pm UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/6 "2025-09-18T14:11:42Z")

</div>

Oh, I didn't check that thoroughly when @lrose told me that. Indeed, there was an import on the first line 🫠

```python
from scripts.tools.auth import auth
@auth
...

```

Removing the import fixes the issue, thanks!

---

<div class="post-metadata">

**Author:** ![mmadariaga](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmadariaga/32/63201_2.png) [@mmadariaga](https://forum.inductiveautomation.com/u/mmadariaga)\
**Post date:** [September 18, 2025, 2:13pm UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/7 "2025-09-18T14:13:52Z")

</div>

The full binding had a check to avoid unwanted values. Looks like the import was the problem 😅

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 18, 2025, 2:16pm UTC](https://forum.inductiveautomation.com/t/calling-function-from-scripting-fails-on-first-load/110745/8 "2025-09-18T14:16:13Z")

</div>

Yup never ever do this for your own scripts!
