# Bug: event.source.setValue on One-Shot Button does not return expected value

**URL:** <https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221>\
**Category:** Ignition\
**Tags:** ignition81, scripting, vision\
**Created:** [August 1, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221 "2023-08-01T14:16:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Micah\_Carr](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@Micah\_Carr](https://forum.inductiveautomation.com/u/Micah_Carr)\
**Post date:** [August 1, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/1 "2023-08-01T14:16:27Z")

</div>

Reading the setValue property on the One Shot Button in a script, returns an object rather than the value of the property.

Ignition Version: **8.1.27 (b2023042509)**

The script (propertyChange):

```auto
if event.propertyName == "value":
	
	print event.newValue
	print event.source.value
	print event.source.setValue
	
	if event.source.value == event.source.setValue:
		print "in"
		
		event.source.value = 0

```

Console Result:

```auto
1
1
<bound method com.inductiveautomation.factorypmi.application.components.PMIControlButton.setValue of com.inductiveautomation.factorypmi.application.components.PMIControlButton[One Shot Button,0,0,68x61,disabled,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.synth.SynthBorder@46f3df97,flags=16777504,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=110,height=27],defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=java.awt.Insets[top=0,left=0,bottom=0,right=0],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Writing...,defaultCapable=true]>

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 1, 2023, 2:20pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/2 "2023-08-01T14:20:40Z")

</div>

> [@Micah\_Carr](#):
>
> `event.source.setValue`

It's supposed to be:`event.source.setValue(PASSNewValueHere)`

This is a method for changing the value not a field.

---

<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:** [August 1, 2023, 2:22pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/3 "2023-08-01T14:22:35Z")

</div>

It's an issue with the name of the property colliding with the name of the property accessor methods for the `value` property.

You won't be able to use Jython's automatic property syntax - you can refer to the value you care about using `event.source.getSetValue()` and `event.source.setSetValue(newValue)`.

---

<div class="post-metadata">

**Author:** ![Micah\_Carr](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@Micah\_Carr](https://forum.inductiveautomation.com/u/Micah_Carr)\
**Post date:** [August 1, 2023, 2:23pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/4 "2023-08-01T14:23:25Z")

</div>

It is a property, that is set in the vision property editor. I should be able to read from it.  
If I wanted to set the value, I would do so directly with event.source.value = 0.

---

<div class="post-metadata">

**Author:** ![Micah\_Carr](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@Micah\_Carr](https://forum.inductiveautomation.com/u/Micah_Carr)\
**Post date:** [August 1, 2023, 2:29pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/5 "2023-08-01T14:29:15Z")

</div>

getSetValue() works.

Still, I selected the property with the scripting "Insert Property Reference" property selector, I believe it should work like any other property selected in this way.

---

<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:** [August 1, 2023, 2:34pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/6 "2023-08-01T14:34:18Z")

</div>

You're not wrong that it should "just work", but in order to actually do that we'd have to add a new property to the one-shot button with a different name and have the property selector use that. Doable, but low priority given the low rate of occurrence and the easy workaround. Plus, what do we name it? `setValue2`?

The underlying issue is that every component property has a `getX` and `setX` method, and there's no way for Jython to distinguish between a call to `setValue()` (meaning update the value property) and `setValue` (meaning give me the current set value of the component).

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 1, 2023, 3:53pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/7 "2023-08-01T15:53:50Z")

</div>

I was mistaken. setValue exists in the class as both a field and a method:  
**Test Button Script:**

```auto
oneShotButton = event.source.parent.getComponent('One Shot Button')
	for field in oneShotButton.getClass().getDeclaredFields():
		if field.name == 'setValue':
			print 'Field Name = ', field.name
			field.setAccessible(True)
			setValueField = field.get(oneShotButton)
			print 'Field Type = ', type(setValueField)
			print
	for method in oneShotButton.getClass().getDeclaredMethods():
		if method.name == 'setValue':
			print 'Method Name = ', method.name
			print type(oneShotButton.setValue)

```

**Output:**

```auto
Field Name = setValue
Field Type = <type 'int'>

Method Name = setValue
<type 'instancemethod'>

```

That said, the declared field is not in [the documentation for that component](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.20/com/inductiveautomation/factorypmi/application/components/PMIControlButton.html). Only the method is listed:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/3/3324c81184a0c20c3c880f4a66e7a5b64bafc030.png)

---

<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:** [August 1, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/8 "2023-08-01T16:17:25Z")

</div>

> [@justinedwards.jle](#):
>
> That said, the declared field is not in [the documentation for that component](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.20/com/inductiveautomation/factorypmi/application/components/PMIControlButton.html). Only the method is listed:

Yeah. It's because Jython. Instead of requiring you to go to the class and reflectively look up the methods as Java does, Jython follows the Python model of allowing you to look up instance methods as first-class objects, so `myClass.myInstanceMethod` == `bound method of myClass`, and `myClass.myInstanceMethod()` == a call to that bound method. It doesn't show in the Javadocs because it's not "real", it's only there inside the Jython environment.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 1, 2023, 4:47pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/9 "2023-08-01T16:47:28Z")

</div>

> [@paul-griffith](#):
>
> It doesn't show in the Javadocs

Looking closer at the docs, the field is technically listed there as an argument in the setSetValue method and as a returned value for the getSetValue method.

...but even so, I realize that my initial answer was correct, and at this point, I've way over analyzed this.

---

<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:** [August 1, 2023, 5:20pm UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/10 "2023-08-01T17:20:04Z")

</div>

> [@justinedwards.jle](#):
>
> I realize that my initial answer was correct

But it wasn't. You were conflating the setter for the `value` NetBeans property with the `setValue` property, whose setter is `setSetValue()`. But the two different NetBeans properties clash in jython because jython exposes both the native java methods and the implicit jython fields. Except it cannot in this case, due to the poor choice of name. (The `setValue` property **could** exist in this scheme if the `value` property **did not** exist.)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 2, 2023, 11:43am UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/11 "2023-08-02T11:43:01Z")

</div>

Yesterday, I was reading and replying to this from my phone, and everything looked good, but this morning, I was reading the forum from my computer, and uggh! ...that screenshot I posted of the setSetValue method rendered offensively large. The text is clear enough that the picture isn't necessary, so I've removed it. My apologies if that came across as obnoxious.

---

<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:** [August 2, 2023, 11:59am UTC](https://forum.inductiveautomation.com/t/bug-event-source-setvalue-on-one-shot-button-does-not-return-expected-value/77221/12 "2023-08-02T11:59:12Z")

</div>

> [@justinedwards.jle](#):
>
> My apologies if that came across as obnoxious.

It did not strike me so. No worries.

FWIW, this topic might help:

> [@"java import" in script](https://forum.inductiveautomation.com/t/java-import-in-script/68953/2):
>
> Standard function in jython. With some quirks: Wildcard imports are not supported for java packages. Jython automatically "wraps" java objects with a dynamic subclass of PyObject, creating matching methods and fields. When such a wrapped object is handed to a true java method that doesn't take a PyObject, but does take the inner java type, the wrapper is automatically stripped back off. Python native types are marshalled into similar java types. SImilar in reverse for java primitive …
