# How to initialize custom parameter at startup

**URL:** <https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 17, 2024, 5:39am UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317 "2024-07-17T05:39:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [July 17, 2024, 5:39am UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/1 "2024-07-17T05:39:25Z")

</div>

Geeezzzz How do you initialize custom parameter/component parameter/embeded view parameter..

I placed my code on Startup Script, I have different result every time..

My initial theory, embedded did not fully loaded, when the init command on startup executed.

I tried Sleep, but still it is hit or miss.

So I did last resort.  
On startup, this time I write to View's Custom Parameter (thinking views custom parameter will wakeup same time with startup), then my embedded component's parameter is bind to view's custom parameter..  
STILL... View's custom parameter would not initialized.

I tried to Switch Off Persistence on the custom variable.  
When the view launch, the custom variable appeared, and with a value from out of no where!! - there should be no value since persistence is Off.

SMH... so I add 2 seconds sleep at the beginning of startup.. works now (i can see custom variable appear with rubbish data, and got initialized.. but really. this solution is not robust.

Does that mean, startup write command is a Miss when the target parameter still not loaded?

Any idea how to properly Initialized components parameter that works all the time?

---

<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 17, 2024, 11:59am UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/2 "2024-07-17T11:59:32Z")

</div>

Use an expression binding that produces a constant. Scripts run in parallel with component operations, and, as you've seen, tend to have race conditions. Use scripts for user-initiated UI events.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [July 17, 2024, 1:52pm UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/3 "2024-07-17T13:52:25Z")

</div>

I added expression binding to my Custom Parameter(statusId).

```python
if({view.params.isNew},"",{view.params.statusId})

```

Upon opening the view on designer.  
statusId has garbage data of 160. (idk where 160 came from)

And the expression bind to statusId did not run - I had to open the binding, then press ok, then it will update.

This is so frustrating.. Hope can get to the bottom of this.

---

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [July 17, 2024, 2:05pm UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/4 "2024-07-17T14:05:07Z")

</div>

Worth noting if you press save in designer when you changed a parameter while it's "playing" the view, it will save that as its initial value.

Seems like you just want this `statusID` you pass down to be a custom parameter? Can you do a parameter binding to the `view.params.statusId`

---

<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 17, 2024, 2:13pm UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/5 "2024-07-17T14:13:55Z")

</div>

That isn't a constant expression. And it references `view.params.` keys that won't be defined on docked views. 🤷‍♂️

Use `view.custom.` instead of `view.params.` in **docked** views. Expression bindings driving these need to only reference session props, constants, or other custom props that receive a value "before" them.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [July 17, 2024, 2:16pm UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/6 "2024-07-17T14:16:32Z")

</div>

Oh, I am referring to a popup view. where I pass in initial data: (isNew, data object)

--edit:  
Technically, it is a Popup form, where user start from blank or use the pass is data..

The problem is, when I launch the popup, I can't write to the fields to initialized it.  
I need to sleep 2 seconds, and write on them..

---

<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 17, 2024, 2:21pm UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/7 "2024-07-17T14:21:15Z")

</div>

Ok. Wrap your references to parameters in `coalesce({view.params.whatever}, someConstant)` that will yield a valid, _temporary_, result prior to parameter initialization.

Make sure parameters are **not** persistent. That way they are **null** before initialization, triggering the `coalesce()` in the moments before everything is initialized. Some bindings might run more than once depending on the (random?) order of initialization.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [July 18, 2024, 1:39pm UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/8 "2024-07-18T13:39:14Z")

</div>

Thank you..

Instead of startup script, I now use binding on all View's Custom Parameter to initialized, what needs to be initialized. Now the writing down to embedded components (via binding to custom parameters) are successful.

---

<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 18, 2024, 1:41pm UTC](https://forum.inductiveautomation.com/t/how-to-initialize-custom-parameter-at-startup/93317/9 "2024-07-18T13:41:39Z")

</div>

custom **properties** , not **parameters**. Terminology matters.

/pedant
