# Property Change Script

**URL:** <https://forum.inductiveautomation.com/t/property-change-script/79761>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 27, 2023, 10:44pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761 "2023-09-27T22:44:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Summer\_L](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Summer\_L](https://forum.inductiveautomation.com/u/Summer_L)\
**Post date:** [September 27, 2023, 10:44pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/1 "2023-09-27T22:44:31Z")

</div>

I currently have a property change script that edits the name of a prop, but the issue is that I only want this script to run once. Any ideas on how to achieve this?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 27, 2023, 11:16pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/2 "2023-09-27T23:16:29Z")

</div>

Your expected sequence of events isn't clear, nor is your intended result. Could you provide some more insight into exactly what it is you're trying to do?

---

<div class="post-metadata">

**Author:** ![Summer\_L](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Summer\_L](https://forum.inductiveautomation.com/u/Summer_L)\
**Post date:** [September 27, 2023, 11:32pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/3 "2023-09-27T23:32:19Z")

</div>

I have a property change script bound to a prop (it's a simple script that changes a string to something more useful to the user) and I want this script to only execute one time, so that the user is able to overwrite this string. Currently, the script runs every time a change occurs, and I want it to only run on the first change. My intended result is the script iterates once.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 27, 2023, 11:36pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/4 "2023-09-27T23:36:57Z")

</div>

The easiest way to manage this is to use a separate property which acts as a flag. It's best to modify the structure of your existing property such that is an object, but this could also be done with two sibling properties.

```auto
myString: {
    value: "original",
    hasChanged: False
}

```

Now modify your change script:

```auto
if not self.custom.myString.hasChanged:
    self.custom.myString.value = "new"
    self.custom.myString.hasChanged = True

```

This will result in the value changing only once before being locked. Note that these are ephemeral properties, and live only as long as the resource does. If you need something more permanent, you'll need to look into using tags or a database implementation along the same lines.

---

<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:** [September 28, 2023, 5:59am UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/5 "2023-09-28T05:59:44Z")

</div>

> [@Summer\_L](#):
>
> I currently have a property change script that edits the name of a prop ...

I think you mean, "that edits the text property of a component". Editing the name of a property doesn't make sense as the user would never see it if it were even possible.

---

<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:** [September 28, 2023, 6:58am UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/6 "2023-09-28T06:58:41Z")

</div>

Wouldn't it be simpler and more obvious to the user to use a button for this ?

---

<div class="post-metadata">

**Author:** ![Summer\_L](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Summer\_L](https://forum.inductiveautomation.com/u/Summer_L)\
**Post date:** [September 28, 2023, 3:08pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/7 "2023-09-28T15:08:12Z")

</div>

This was really helpful, thanks.

---

<div class="post-metadata">

**Author:** ![Summer\_L](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Summer\_L](https://forum.inductiveautomation.com/u/Summer_L)\
**Post date:** [September 29, 2023, 6:31pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/8 "2023-09-29T18:31:43Z")

</div>

> [@cmallonee](#):
>
> ```auto
> myString: {
> value: "original",
> hasChanged: False
> }
> 
> ```

I've been trying to do this, but when I try to add a new property value (i.e. hasChanged) via a script to a start up event it doesn't show up in the Property Editor. I then I try to manually add a new value, and get an error saying "Property 'hasChanged' has not been defined and the schema does not allow additional properties."

---

<div class="post-metadata">

**Author:** ![Summer\_L](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Summer\_L](https://forum.inductiveautomation.com/u/Summer_L)\
**Post date:** [September 29, 2023, 6:39pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/9 "2023-09-29T18:39:36Z")

</div>

No, a button would be unintuitive for what I'm doing.

---

<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:** [September 29, 2023, 7:24pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/10 "2023-09-29T19:24:35Z")

</div>

> [@Summer\_L](#):
>
> ... but when I try to add a new property value (i.e. hasChanged) via a script to a start up event it doesn't show up in the Property Editor.

Create the custom property manually. Then change it by script. Here I've added @cmallonee's code to the button's Events | onActionPerformed | Script.

![Button hasChanged](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e0fd27abd31961f834331fc76ad3f2379bde7774.gif)

---

<div class="post-metadata">

**Author:** ![Summer\_L](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Summer\_L](https://forum.inductiveautomation.com/u/Summer_L)\
**Post date:** [September 29, 2023, 7:48pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/11 "2023-09-29T19:48:43Z")

</div>

As I mentioned, I'm unable to add a custom property manually, without getting the error "Property 'hasChanged' has not been defined and the schema does not allow additional properties."

---

<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:** [September 29, 2023, 7:54pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/12 "2023-09-29T19:54:51Z")

</div>

> [@Summer\_L](#):
>
> the schema does not allow additional properties.

That sounds like a problem with the JSON.  
`myString` should be an object type.  
Right-click on `custom.myString` | Structure | Change to and check that it has been declared as an object.

---

<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:** [September 29, 2023, 8:04pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/13 "2023-09-29T20:04:51Z")

</div>

Make sure you're creating your own properties in the "CUSTOM" scope, not within one of the system defined areas like props or meta.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 29, 2023, 8:33pm UTC](https://forum.inductiveautomation.com/t/property-change-script/79761/14 "2023-09-29T20:33:39Z")

</div>

The `PROPS`, `POSITION`, and `META` categories have a prescribed set of properties which are allowed and the structure of those properties is more-or-less locked. The `CUSTOM` category is the only area you may define your own properties.
