# Momentary Button with Confirmation Pop-up

**URL:** <https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303>\
**Category:** Ignition\
**Tags:** ignition81, scripting, vision\
**Created:** [March 13, 2024, 8:14pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303 "2024-03-13T20:14:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derek\_Lyons](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/derek_lyons/32/54204_2.png) [@Derek\_Lyons](https://forum.inductiveautomation.com/u/Derek_Lyons)\
**Post date:** [March 13, 2024, 8:14pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/1 "2024-03-13T20:14:24Z")

</div>

Good day all,

I'm trying to make a momentary button but with a confirmation pop-up.

I noticed the option for the confirmation pop-up is only inherent to a few components (2-State Toggle, One-Shot Button). I tried using the one-shot button but it does not work how I expected and don't want my OPC client to have to send a response back after receiving the one-shot.

That being said, I was trying to be clever and use the following script on a momentary button but neither attempts have worked.

ATTEMPT #1: Reading and writing direct with custom template parameter. Template parameter bound to OPC tag.  
RESULT: Works inconsistently. Sometimes the OPC tag changes, sometimes it does not. Sometimes gets latched on.

```auto
if (system.gui.confirm('Are you sure?', 'Confirm')):
	event.source.parent.Copy_PB = 1
	
	if (event.source.parent.Copy_PB == 1):
		event.source.parent.Copy_PB = 0
	else:
		event.source.parent.Copy_PB = 0

```

ATTEMPT #2: Reading and writing direct with OPC tags.  
RESULT: Allows writing to the tag but then script crashes after that.

```auto
if (system.gui.confirm('Are you sure?', 'Confirm')):
	system.tag.writeBlocking('X', 1)

	if system.tag.readBlocking('X', 1):
		system.tag.writeBlocking('X', 0)
	else:
		system.tag.writeBlocking('X', 0)

```

What other alternatives came I look into to get the functionality I'm looking for?

Since I think my first attempt was failing because of timing, I considered using some kind of delay script but I heard horror stories about that causing problems.

Thanks!

---

<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:** [March 13, 2024, 8:28pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/2 "2024-03-13T20:28:21Z")

</div>

How can this possibly work? The user would have to release the momentary button to click on the confirmation, so the button isn't pressed any more. Are you sure you want a momentary button?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [March 13, 2024, 8:29pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/3 "2024-03-13T20:29:27Z")

</div>

I think he might be trying to write a 1 then a 0 in quick succession after confirmation, unless I'm mis-understanding the code.

---

<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:** [March 13, 2024, 8:30pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/4 "2024-03-13T20:30:15Z")

</div>

Maybe, but confirmation is before **any** action, so that can't work.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [March 13, 2024, 8:32pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/5 "2024-03-13T20:32:51Z")

</div>

Ah, I see what you mean, I was thinking from using a momentary button as a one off click, not holding it.

@Derek_Lyons If you need confirmation on a button that needs to be held, have some other component that enables/disables the actual momentary button that will be held. That toggle can be completely on ignition side, its just so operators have that extra step to confirm that yes they want to hold this button. You can also have a timer that resets the toggle after a certain period of the button not being pressed if needed.

---

<div class="post-metadata">

**Author:** ![Derek\_Lyons](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/derek_lyons/32/54204_2.png) [@Derek\_Lyons](https://forum.inductiveautomation.com/u/Derek_Lyons)\
**Post date:** [March 14, 2024, 11:59am UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/6 "2024-03-14T11:59:37Z")

</div>

@ryan.white Your first comment was spot on. I want a momentary button to pulse a boolean OPC tag. If the operator presses the button, a confirmation window will pop up. If the user intended on pressing the button, the operator presses "YES", and the boolean is pulsed hi then lo. If the button press was a mistake, the operator presses "NO" and nothing happens.

Based on your second comment, it sounds like my best option is a toggle button with a delay timer to reset the toggle back lo after a period of time. Is that correct?

---

<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:** [March 14, 2024, 12:08pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/7 "2024-03-14T12:08:43Z")

</div>

No, your UI cannot reliably ensure that the reset to low will be delivered. If you need to ensure it is low except when desired, run a gateway timer event that constantly writes to it based on timestamp (in a memory tag). The ordinary button's actionPerformed event would set that timestamp to `now()` + desired pulse duration. The timer event would compute `now() < {timstamp tag}` and write the result if it doesn't match the signal's current value.

This ensures the signal gets reset if your client freezes just when the button is clicked.

---

<div class="post-metadata">

**Author:** ![Derek\_Lyons](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/derek_lyons/32/54204_2.png) [@Derek\_Lyons](https://forum.inductiveautomation.com/u/Derek_Lyons)\
**Post date:** [March 14, 2024, 12:20pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/8 "2024-03-14T12:20:49Z")

</div>

@pturmel Thanks Phil! That's a clever idea. Thank you for this solution!

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [March 14, 2024, 12:38pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/9 "2024-03-14T12:38:43Z")

</div>

Another option is set on the confirmation and have the OPC device reset when it receives the signal. Can't get much simpler than that.

---

<div class="post-metadata">

**Author:** ![Derek\_Lyons](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/derek_lyons/32/54204_2.png) [@Derek\_Lyons](https://forum.inductiveautomation.com/u/Derek_Lyons)\
**Post date:** [March 14, 2024, 4:39pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/10 "2024-03-14T16:39:20Z")

</div>

Just wanted to pop in again and say I was able to get the momentary button to work the way I was looking for with the following script.

```auto
if system.gui.confirm('Are you sure?', 'Confirm'):
	event.source.parent.Copy_PB = 1
	
	def setLoRecipeCopyPB():
		event.source.parent.Copy_PB = 0
		
	system.util.invokeLater(setLoRecipeCopyPB,1000)

```

@pturmel I think this was kind of what you were suggesting but, instead, setting it up as a gateway event script that would execute the function when it sees the appropriate boolean go Hi. That way if my client crashes mid button press, it doesn't get latched Hi.

---

<div class="post-metadata">

**Author:** ![Derek\_Lyons](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/derek_lyons/32/54204_2.png) [@Derek\_Lyons](https://forum.inductiveautomation.com/u/Derek_Lyons)\
**Post date:** [March 14, 2024, 4:42pm UTC](https://forum.inductiveautomation.com/t/momentary-button-with-confirmation-pop-up/87303/11 "2024-03-14T16:42:56Z")

</div>

Thanks @jlandwerlen. Was considering that option also if all else failed.
