# Dynamically Adding Value Change Script to a component propetry via Button Click in Ignition Perspective

**URL:** <https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869>\
**Category:** Ignition\
**Tags:** ignition81, python, ignition80, scripting, perspective\
**Created:** [May 5, 2025, 11:11am UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869 "2025-05-05T11:11:57Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![ARIFRAHUMAN\_A](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ARIFRAHUMAN\_A](https://forum.inductiveautomation.com/u/ARIFRAHUMAN_A)\
**Post date:** [May 5, 2025, 11:11am UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/1 "2025-05-05T11:11:57Z")

</div>

I have a Label and a Button in Perspective. When the button is clicked, I want to dynamically add a new value change script to the Label's `text` property. Specifically, the number of lines I write in the button's script should be added to the value change script of the Label. Has anyone implemented this kind of functionality before? If so, please share your solution or guidance

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 5, 2025, 11:19am UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/2 "2025-05-05T11:19:18Z")

</div>

What is the real problem you are trying to solve. What you are proposing is strange and there must be a better way to do it.

---

<div class="post-metadata">

**Author:** ![ARIFRAHUMAN\_A](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ARIFRAHUMAN\_A](https://forum.inductiveautomation.com/u/ARIFRAHUMAN_A)\
**Post date:** [May 5, 2025, 11:33am UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/3 "2025-05-05T11:33:06Z")

</div>

When I click the button, I want the script `system.perspective.sendMessage('test', {})` to be injected into the Label component's `onValueChange` script. Is this possible?

I'm asking because I was able to inject script lines into a tag's value change event, so I'm wondering if a similar approach is possible for Perspective components.

---

<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:** [May 5, 2025, 12:28pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/4 "2025-05-05T12:28:44Z")

</div>

> [@ARIFRAHUMAN\_A](#):
>
> Is this possible?

While, it may be possible through some fancy manipulation of the view files JSON on the Gateway, there would be a large delay, 5 secs by default IIRC.

The real question is why? Why do you need to inject this function into a script? Just put it there to begin with.

You couldn't pay me enough to implement the ability of an end user to "add arbitrary code" into a view.

Also, in python functions are objects, and they can be passed around just like other objects you may be more familiar with.

---

<div class="post-metadata">

**Author:** ![ARIFRAHUMAN\_A](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ARIFRAHUMAN\_A](https://forum.inductiveautomation.com/u/ARIFRAHUMAN_A)\
**Post date:** [May 5, 2025, 1:51pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/5 "2025-05-05T13:51:43Z")

</div>

I didn't fully understand your question. What I'm trying to ask is whether this functionality is currently possible, as it is essential for my development requirements. That’s why I’m checking if this feature is officially supported. If anyone knows of an alternative approach or has any relevant resources, please share the links or provide guidance. Any support on this would be greatly appreciated.

---

<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:** [May 5, 2025, 1:58pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/6 "2025-05-05T13:58:01Z")

</div>

Currently possible and officially supported are not mutually exclusive.

> [@ARIFRAHUMAN\_A](#):
>
> as it is essential for my development requirements

What I, and I believe @Transistor are trying to understand is why this is "essential". What functionality is this empowering?

> [@ARIFRAHUMAN\_A](#):
>
> If anyone knows of an alternative approach

Very difficult for us to suggest alternative approaches when we don't know what it is you're really trying to achieve. And no, injecting active code into an event script at runtime, is not what you're trying to achieve, that is the means you are _attempting_ to get to some end.

What is the end result that you want to achieve?

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 5, 2025, 2:04pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/7 "2025-05-05T14:04:56Z")

</div>

I can't imagine any case where this is necessary where you couldn't solve this by having onValueChange script read something like

```python
for message in system.tag.readBlocking(tagpath):
    system.perspective.sendMessage(message, {})

```

and then the onClick just appends to the tagpath

---

<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:** [May 5, 2025, 2:20pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/8 "2025-05-05T14:20:21Z")

</div>

I wouldn't involve tags just yet.

@ARIFRAHUMAN_A : What @lrose and @Transistor are hinting at is this: [https://xyproblem.info/](https://xyproblem.info/)  
They're saying you're looking for a way to do what you think is the solution to your problem, instead of asking how to solve your problem.

Tell us what this would solve, and we might find a better way to solve it.

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 5, 2025, 2:20pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/9 "2025-05-05T14:20:42Z")

</div>

Fair 🙂

---

<div class="post-metadata">

**Author:** ![ARIFRAHUMAN\_A](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ARIFRAHUMAN\_A](https://forum.inductiveautomation.com/u/ARIFRAHUMAN_A)\
**Post date:** [May 5, 2025, 2:24pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/10 "2025-05-05T14:24:40Z")

</div>

At the end of the process, I am using an Accordion component where the `items` data is passed dynamically. Each item contains an `expanded` property, and I want to inject a value change script into that property. The goal is to inject the script at the time the `items` data is assigned to the Accordion. Specifically, I want the script to execute and call a message handler (e.g., `system.perspective.sendMessage`) when an item’s expand icon is clicked (i.e., when the `expanded` property changes). This is the functionality I’m trying to achieve.

---

<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:** [May 5, 2025, 2:25pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/11 "2025-05-05T14:25:53Z")

</div>

Add a `message_handler` parameter to your repeated view, and use that parameter as the argument to `system.perspective.sendMessage`

---

<div class="post-metadata">

**Author:** ![ARIFRAHUMAN\_A](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ARIFRAHUMAN\_A](https://forum.inductiveautomation.com/u/ARIFRAHUMAN_A)\
**Post date:** [May 5, 2025, 2:31pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/12 "2025-05-05T14:31:23Z")

</div>

Hi @nminchin,  
Do you have any idea or suggestions regarding this requirement? I’m trying to dynamically inject a value change script into the `expanded` property of an Accordion component item. it will very helpful for me

---

<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:** [May 5, 2025, 2:38pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/13 "2025-05-05T14:38:43Z")

</div>

Dont inject the script, just make its parameters dynamic.  
Or is there a reason this wouldn't be enough ?

---

<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:** [May 5, 2025, 2:39pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/14 "2025-05-05T14:39:44Z")

</div>

> [@ARIFRAHUMAN\_A](#):
>
> The goal is to inject the script at the time the `items` data is assigned to the Accordion.

I see no need to inject a script.

Just place the script on the view that is being repeated in the Accordion. Better yet, place the actual script in a project library, and call out to that script from the repeated view. Change the parameters you send to the function.

You have still yet to say _ **why** _ you feel you need to inject this script.

Also, please don't ping random users. If Nick felt like he had something to add, he would post a reply.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 5, 2025, 4:35pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/15 "2025-05-05T16:35:47Z")

</div>

Add the message handler names and payloads to your items array.

 ![Accordion MessageHandler](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c095cf46348bdb7bba442b7649bf26ccbf286d2.png)

On the Accordion component Event | onItemExpanded | Script use something like the following:

```python
def runAction(self, event):
	handler = self.props.items[event.index].messageHandlerName
	if handler is None:
		return
	system.perspective.sendMessage(
		handler, 
		self.props.items[event.index].messageHandlerPayload, 
		scope = "view"
	)

```

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 5, 2025, 6:15pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/16 "2025-05-05T18:15:47Z")

</div>

yep, this works and is cleaner than the tag idea

---

<div class="post-metadata">

**Author:** ![ARIFRAHUMAN\_A](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ARIFRAHUMAN\_A](https://forum.inductiveautomation.com/u/ARIFRAHUMAN_A)\
**Post date:** [May 6, 2025, 5:23am UTC](https://forum.inductiveautomation.com/t/dynamically-adding-value-change-script-to-a-component-propetry-via-button-click-in-ignition-perspective/105869/17 "2025-05-06T05:23:24Z")

</div>

Thanks, @Transistor That's a good idea — I'll try it. 👏🙂
