# Value of property before binding is executed in perspective

**URL:** <https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 31, 2024, 1:36pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977 "2024-07-31T13:36:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [July 31, 2024, 1:36pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/1 "2024-07-31T13:36:20Z")

</div>

Hi,

I'm trying to set a default value for a property before the binding is executed in Perspective.

Here's the situation:

I have a button whose text is bound to a custom property called "datetime" The "datetime" value is only available after 500 ms, which is the time it takes for the binding expression to evaluate in the view.

During the initial 0-500 ms period, the button displays the text "button," which is not what I want. I would prefer it to show something like "loading" until the actual date is available.

I've tried using a persistent property, but if I save my project while a date is shown, that date becomes the default value.

Do you have any suggestions on how to resolve this issue?

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [July 31, 2024, 1:41pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/2 "2024-07-31T13:41:01Z")

</div>

@pturmel do you have any idea, please ?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 31, 2024, 1:41pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/3 "2024-07-31T13:41:12Z")

</div>

Set the property back to transient, and try something like `coalesce(path.to.property, default)`.  
I'd expect the prop to be `null` before the binding evaluates.

But... 500ms ? Where does the data come from ?

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [July 31, 2024, 1:47pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/4 "2024-07-31T13:47:48Z")

</div>

> [@pascal.fragnoud](#):
>
> coalesce

What do you mean by "set the property back to transient" ?

I tried the function coalesce(), but the result is always the same.

500ms it's the approximate time to evaluate binding expression, before evaluation the button text shows "button".

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 31, 2024, 1:50pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/5 "2024-07-31T13:50:31Z")

</div>

Transient is the opposite of persistent. So, make it not persistent, like it was before.  
Without this, The property won't have a value, so you should be able to use `coalesce`.

My bindings never took 500ms to evaluate. Hence my question: What is it evaluating ?

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [July 31, 2024, 2:05pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/6 "2024-07-31T14:05:02Z")

</div>

> [@pascal.fragnoud](#):
>
> s the opposite of persistent.

I created a startup event on my view:

 ![Screenshot 2024-07-31 155647](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/6/56dd46bcdcf432480b67ac429237bdb659f2e9e8.jpeg)

I set custom property of my button named "datetime" to the value returned by the function (simple function, does some string calculations).

 ![Screenshot 2024-07-31 155908](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/3931ad7b00881df65dc1c5fadf48249a14aa8ef3.jpeg)

Than, I bind the button text value with this expression.

When I load the view the button text shows button for very short time (it approximately 500ms).

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 31, 2024, 2:08pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/7 "2024-07-31T14:08:43Z")

</div>

Get rid of the startup script and use a binding on the `datetime` property.  
The binding would look something like this:

```python
runScript(getFirstShiftStartDateTime, 0)

```

If it takes 500ms to load, that's because your script takes 500ms to execute.  
Are you doing I/O operations in it ?  
Can you show the whole script ?

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [July 31, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/8 "2024-07-31T14:11:52Z")

</div>

Here is the whole script, added a line to edit the text at start, the button text appears although for approximately 300ms then "Hiiiii" appears in a second time.

 ![Screenshot 2024-07-31 160807](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c40dcd58f8475e9936594851e2391cabdf4e36c8.jpeg)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 31, 2024, 2:20pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/9 "2024-07-31T14:20:09Z")

</div>

I meant the `settings.getFirstShiftStartDateTime` function's code.

I really mean it: Use bindings, not init scripts. These scripts go in the opposite direction of Ignition's philosophy.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 31, 2024, 2:32pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/10 "2024-07-31T14:32:17Z")

</div>

> [@pascal.fragnoud](#):
>
> Use bindings, not init scripts

Especially for any "open" script. Ignition caches all kinds of things and may not run such events when you think it should. Use bindings.

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [July 31, 2024, 2:34pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/11 "2024-07-31T14:34:36Z")

</div>

I tried to do what you suggested but result is always the same, it seems like it takes time to run binding expression.

 ![Screenshot 2024-07-31 163056](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/06fa4ddad4ab5744290c2bc499c7b1973fd243d0.jpeg)  
 ![Screenshot 2024-07-31 163129](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c39b88f958d5d9992200c79035130cd09bdc789.jpeg)  
 ![Screenshot 2024-07-31 163231](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/7/a729fa2b20fa2d59c9a84391eb10ff18d168485b.jpeg)  
 ![Screenshot 2024-07-31 163257](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b9754ea55cbac613859de4af12672a908b9df448.jpeg)

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [July 31, 2024, 2:39pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/12 "2024-07-31T14:39:54Z")

</div>

I tried using this binding but it works the same, the problem is always there.

 ![Screenshot 2024-07-31 163815](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/e/5ec8376da16536253090de3ce39ba85e012e2364.jpeg)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 31, 2024, 2:40pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/13 "2024-07-31T14:40:20Z")

</div>

That's not how `coalesce` works. `dateFormat` will never return a null, so `coalesce` won't do anything.  
try this instead:

```python
if (isNull({this.custom.datetime}),
  "loading...",
  dateFormat({this.custom.datetime}, 'dd-MM hh:mm')
)

```

I suggest you read this:

> [@Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831):
>
> This thread is intended as a short help file for all those struggling to post formatted code on the forum. Code block formatting Posting formatted code on the forum (and most others) is as simple as selecting the code and pressing the \</\> button. It works the same as applying Bold or Italic styles to your document. It preserves indentation and applies syntax highlighting. [How to post code] Note that all the \</\> button does is add three backticks ``` on the line before the code block and anot…

edit: that shift script looks funky to me. It seems dates are strings, but you're getting them from built-in features. There's something weird here.

edit again:  
yep they're strings:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/5/55b1307cd12029fe483357aaf9dffff0e811f070.png)  
I'm not sure what it's supposed to represent, and there's no details in the docs

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [August 1, 2024, 6:43am UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/14 "2024-08-01T06:43:08Z")

</div>

The binding it self takes time to execute when a view is loaded see the video:

> **[IMG\_1714 (1).gif](https://wetransfer.com/downloads/1cdf00c3179bc622abc1e175f7edb0ae20240801064236/3e1547)**
>
> 1 file sent via WeTransfer, the simplest way to send your files around the world

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [August 1, 2024, 8:05am UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/15 "2024-08-01T08:05:08Z")

</div>

The problem is that button component shows text "button" by default before the binding is evaluated when text is not persistante.

Edited:

If you just try add button anywhere and set text property to not persistante, the text that will be shown is "Button" by default and i think that it is a bug.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 1, 2024, 10:45am UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/16 "2024-08-01T10:45:35Z")

</div>

You should just paste/attach images/gifs/videos directly into your posts rather than uploading them to other sites that will most likely delete them

Edit: I just realised it was 35MB for a gif using dithering??  
Scratch that, use a proper screen recorder like ScreenToGif. That video should be 1MB max

---

<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:** [August 1, 2024, 3:11pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/17 "2024-08-01T15:11:47Z")

</div>

> [@Mehdi\_MECHEDAL](#):
>
> If you just try add button anywhere and set text property to not persistante, the text that will be shown is "Button" by default and i think that it is a bug.

Why would the text of a button not be persitant? Just because it's behavior is unexpected by you, doesn't mean that it's unexpected behavior for the developers.

I understand what you are saying the issue is, but what I am interested in is why? Why are you changing the text on a button?

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [August 2, 2024, 6:41am UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/18 "2024-08-02T06:41:31Z")

</div>

It's a button which will display the start date of production of my machine and as i click i will get the previous date and so on. At the view startup, the button displays "button" before its gets the right date.

---

<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:** [August 2, 2024, 12:11pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/19 "2024-08-02T12:11:57Z")

</div>

> [@Mehdi\_MECHEDAL](#):
>
> as i click i will get the previous date and so on

I understand that it’s a button that is displaying a date. That’s more What the button is doing not why.

The text could just as easily say “Previous Date” and be persistent and then your problem presumably goes away. But without understanding why you’re changing the text on the button rather than in a datetime component, we can’t really suggest any other work around than “deal with it”.

I don’t think this is a bug, I just think the default value is “Button” when the value is null.

At the start-up for every non-persistent binding the value will be null.

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [August 2, 2024, 12:35pm UTC](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977/20 "2024-08-02T12:35:03Z")

</div>

yes i tried your solution, but i faced new issue which has the same cause, if i want to disable the button when the date is after now, i will get the button enabled before the expression executes.

[Next page](https://forum.inductiveautomation.com/t/value-of-property-before-binding-is-executed-in-perspective/93977.md?page=2)
