# Perspective: Cannot update label with popup response text

**URL:** <https://forum.inductiveautomation.com/t/perspective-cannot-update-label-with-popup-response-text/38369>\
**Category:** Ignition\
**Created:** [September 3, 2020, 8:16pm UTC](https://forum.inductiveautomation.com/t/perspective-cannot-update-label-with-popup-response-text/38369 "2020-09-03T20:16:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [September 3, 2020, 8:16pm UTC](https://forum.inductiveautomation.com/t/perspective-cannot-update-label-with-popup-response-text/38369/1 "2020-09-03T20:16:15Z")

</div>

In perspective, I have a view with a button and a label (“Label\_0”). The button “onClick” event script is as follows:

```auto
def runAction(self, event):
	def func():
		system.perspective.openPopup('myPopup', 'Application/confirm', id = 99, params = {'id':99 }, showCloseIcon = False, modal = True, draggable = False)

		if self.session.custom.popup_response == "CANCEL":
			self.getSibling("Label_0").props.text = "XX"
		else:
			self.getSibling("Label_0").props.text = "OO"
	
	func()

```

The “Application/confirm” view has two buttons (“OK” and “CANCEL”), whose code is as follows:

```auto
# script for "OK" button
def runAction(self, event):
	self.session.custom.popup_response = "OK"
	system.perspective.closePopup(id = self.view.params.id)

```

```auto
# script for "CANCEL" button
def runAction(self, event):
	self.session.custom.popup_response = "CANCEL"
	system.perspective.closePopup(id = self.view.params.id)

```

Now, if I run the code, the popup shows, but it appears that the text of “Label\_0” is updated.with the desired text only when I reopen the popup, not when it closes.  
Sample sequence: I open the popup, choose “OK”, the popup closes, Label\_0 is not updated. I open the popup again, now I can see (shaded under the popup) Label\_0 now showing “OO”. I choose “CANCEL”, the popup closes, and Label\_0 still shows “OO”. I reopen the popup, and _now_ Label\_0 changes to “XX”. Etc. etc.

Am I doing something wrong?

---

<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 3, 2020, 8:27pm UTC](https://forum.inductiveautomation.com/t/perspective-cannot-update-label-with-popup-response-text/38369/2 "2020-09-03T20:27:32Z")

</div>

> [@jross2020](#):
>
> Am I doing something wrong?

Yes.

It's important to note that Perspective Popups do not behave like Vision Popups. There is no "response" from the Popup. The script which opens your Popup opens the Popup correctly, but then IMMEDIATELY checks the status of a session property before a user could possibly interact with the Popup, so when you check `session.custom.popup_response`, you're going to obtain whatever value it had before the Popup was opened - not the value based off of the current user interaction.

I recommend removing the `if/else` block from your code, and binding the text for `Label_0` to the session property in question while using a script transform like this:

```auto
default_text = '' # what value do you want the Label to have before a user confirms or cancels?
if value:
    if value == 'OK':
        return '00'
    if value == 'CANCEL'
        return 'XX'
return default_text

```

Keep in mind this value is retained for the life of the session, so if a user visits this View again the session property will still have a value and so the Label will still display the last value supplied.

---

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [September 3, 2020, 8:30pm UTC](https://forum.inductiveautomation.com/t/perspective-cannot-update-label-with-popup-response-text/38369/3 "2020-09-03T20:30:35Z")

</div>

Unfortunately, the above is a simplified reproducer of the issue. The actual code has, instead of the “Label\_0” update, a “return” statement that is supposed to return the chosen value to another function in another part of the code (that does or doesn’t carry on with its job depending on the user’s response to the popup). Is there a way to get this behavior (“Vision-like”, if you want) with Perspective?

---

<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 3, 2020, 8:39pm UTC](https://forum.inductiveautomation.com/t/perspective-cannot-update-label-with-popup-response-text/38369/4 "2020-09-03T20:39:29Z")

</div>

There is no way to have your **code** “wait” on a response form a Popup because the Popup will never return anything.

What I usually recommend when users use Popups is to familiarize yourself with `system.perspective.sendMessage()` ([docs](https://docs.inductiveautomation.com/display/DOC80/system.perspective.sendMessage)). Have the popup buttons invoke a sendMessage call, and have the main view listen with a Message Handler. You can then have the main view take no action based on the Popup until a user has actually performed an action within the Popup. This, in essence, causes the **View** to wait for a response - as opposed to your script.

---

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [September 3, 2020, 8:41pm UTC](https://forum.inductiveautomation.com/t/perspective-cannot-update-label-with-popup-response-text/38369/5 "2020-09-03T20:41:56Z")

</div>

I used sendMessage in the past so I know it, adapting this case to the message paradigm will require a significant code refactoring, but if it’s the only way then so be it. Thanks!
