# System of popup depending of the user

**URL:** <https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 18, 2024, 12:57pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442 "2024-01-18T12:57:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 18, 2024, 12:57pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/1 "2024-01-18T12:57:25Z")

</div>

Hi all,

I'd like to create a system that shows a popup when someone logs in my app on perspective. The purpose is to show a message of an update so the user can be aware of it, and then when he acknowledges it, the popup no longer appears when he logs in.  
I don't know how I can run a script when someone logs in.  
Any idea ?

---

<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:** [January 18, 2024, 1:24pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/2 "2024-01-18T13:24:32Z")

</div>

Things to investigate:

- On your primary view (or home page), right-click on the _root_ → Configure Events → onStartup → Script.
- You'll need to run a query to see if the user has already seen the notification and then open the popup, if required. Make it Modal.
- You'll need to record the acknowledgement in the database to prevent subsequent popups for that notice.

Things to watch: if your user can bypass the home page by providing a direct URL you will have to use a different method. This might be to create the event on one of the Page Configuration views (left sidebar or banner) that are always present.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 18, 2024, 1:57pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/3 "2024-01-18T13:57:58Z")

</div>

How is working the 'onStart' ? If the main page has already been opened by a user, and another one comes and logs in, will the script still run ? The 'log in' button is on the main page.

I was thinking to store the acknowledgement in a tag dataset at the beginning, then if the system is working I guess I'll store in the database

---

<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:** [January 18, 2024, 2:29pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/4 "2024-01-18T14:29:34Z")

</div>

Yes, you are correct that there's a problem if the page is already open.

I presume then that the home page login button is running an onActionPerformed event with a Login action? If so, you could change this to a script, use the [system.perspective.login - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.perspective.login) function and follow that with your "notification required" check and optional popup.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 18, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/5 "2024-01-18T15:03:54Z")

</div>

Yes you are right!

So I tried this, but my popup doesn't show up. I think that as the 'system.perspective.login' brings me to another page to log in and then takes me back to the page of my project, the script doesn't run after the line of the login (or maybe it runs but as I leave the page and then comeback, it's resetting it). I've put a line to put a text in a label just after the line of the login command, and when I come back to the page nothing changed for the label.

---

<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:** [January 18, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/6 "2024-01-18T15:20:20Z")

</div>

Hmmm! I know that if you were to run a login action followed by a script action on the button event that they run asynchronously and that can cause problems. That's why I suggested doing it in a script so that you'd be sure of the sequence.

Someone else may be able to see the problem.

Meanwhile, I suggest you post the event script here (as formatted code).

Last thought: did you add the `modal = True` parameter to the [system.perspective.openPopup - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.perspective.openPopup)?

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 18, 2024, 4:26pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/7 "2024-01-18T16:26:10Z")

</div>

I tried with a script and still not working unfortunately

Here's my function:

```auto
def test_popup():
	system.perspective.login(forceAuth=True)
	system.perspective.openPopup("Test_Popup",'Popup/testPopup', showCloseIcon = False, resizable = False, draggable = False, modal = True)

```

I just call this function in the event of the button.

And thanks for the modal parameter! I didn't know about it and it will be useful for something else

---

<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:** [January 18, 2024, 5:10pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/8 "2024-01-18T17:10:49Z")

</div>

> [@Alexandre\_Pasquereau](#):
>
> when someone logs in

Instead of a script within the onStartup Event of a Page, you should place a change script on some piece of the `user` object within session properties - most likely `username`.

To track who has viewed this Popup over time, you will need to incorporate a database. I'll leave managing this data to you, but your change script will look something like this:

```python
if currentValue and currentValue.value: # length check to avoid None
    # check database
    popup_already_viewed = system.db.runPrepQuery(...)
    if not popup_already_viewed:
        """
        The Session-level properties have no page context/thread,
        so you will need to open this popup on every page
        of the session.
        """
        for session in system.perspective.getSessionInfo():
            if session.id = self.props.id:
                for pageId in session.pageIds:
                    system.perspective.openPopup("PopupId", "ViewName", modal=True, sessionId=self.props.id, pageId=pageId)

```

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 19, 2024, 2:51pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/9 "2024-01-19T14:51:02Z")

</div>

Okay sounds good thanks! I will try this

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 22, 2024, 2:30pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/10 "2024-01-22T14:30:55Z")

</div>

So I tried it but the popup doesn't show up.

I've put this script in the Change Script of Username:

```auto
	if currentValue and currentValue.value: # length check to avoid None
	    # check database
	    if currentValue == "AP" or currentValue.value == "AP":
		    popup_already_viewed = system.tag.read("[default]Test Popup").value
		    if not popup_already_viewed:
		        """
		        The Session-level properties have no page context/thread,
		        so you will need to open this popup on every page
		        of the session.
		        """
		        for session in system.perspective.getSessionInfo():
		            if session.id == self.props.id:
		                for pageId in session.pageIds:
		                    system.perspective.openPopup("Test_Popup", "Popup/testPopup", modal=True, sessionId=self.props.id, pageId=pageId)

```

I just changed the test if the popup is already viewed by a boolean tag (temporarily until it's working).

---

<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:** [January 22, 2024, 2:39pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/11 "2024-01-22T14:39:57Z")

</div>

You're nesting about six levels deep. It's time to de-nest. I got some good tips from the first part of [Why you shouldn't nest your code](https://www.youtube.com/watch?v=CFRhGnuXG-4&t=150s).

This doesn't address why your code isn't working but it may help you to figure it out. Here's my attempt (but there are many here much better with Python):

```auto
if not currentValue or not currentValue.value: # length check to avoid None
    return

# check database
if currentValue != "AP" and currentValue.value != "AP":
    return

popup_already_viewed = system.tag.read("[default]Test Popup").value
if popup_already_viewed:
    return
    
"""
The Session-level properties have no page context/thread,
so you will need to open this popup on every page
of the session.
"""
for session in system.perspective.getSessionInfo():
    if session.id != self.props.id:
        continue # Skip to next session.
    for pageId in session.pageIds:
        system.perspective.openPopup("Test_Popup", "Popup/testPopup", 
                    modal=True, sessionId=self.props.id, pageId=pageId
    )

```

---

<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:** [January 22, 2024, 3:45pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/12 "2024-01-22T15:45:36Z")

</div>

> [@Alexandre\_Pasquereau](#):
>
> So I tried it but the popup doesn't show up.

Do your Gateway logs contain any errors logged due to this script?

Also, I forgot this route will not work for projects which REQUIRE authentication, as the `username` value will not "change", it will initialize as the user's name - bypassing the change script.

I tried out the script and it worked 100% as expected on a project which did not require authentication.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 22, 2024, 4:31pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/13 "2024-01-22T16:31:55Z")

</div>

In the logs I have this error:  
Error running property change script on session.props.auth.user.userName: Traceback (most recent call last): File "function:valueChanged", line 15, in valueChanged at com.inductiveautomation.perspective.gateway.model.PageModel.send(PageModel.java:384) at com.inductiveautomation.perspective.gateway.model.PageModel.send(PageModel.java:365) at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.lambda$popupAction$21(PerspectiveScriptingFunctions.java:778) at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.lambda$operateOnPage$0(AbstractScriptingFunctions.java:82) at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnSession(AbstractScriptingFunctions.java:120) at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnPage(AbstractScriptingFunctions.java:47) at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.popupAction(PerspectiveScriptingFunctions.java:758) at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.openPopup(PerspectiveScriptingFunctions.java:240) at jdk.internal.reflect.GeneratedMethodAccessor456.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.io.IOException: java.io.IOException: Channel is not set.

No idea of what's the problem... Any clue on what is this 'channel' ?

I don't understand, how can it works if you don't use the authentication ?

---

<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:** [January 22, 2024, 4:55pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/14 "2024-01-22T16:55:30Z")

</div>

Some projects do not require authentication. When those sessions start, `username` is `null`. When a user logs in, the username _changes_ to the user's username, thus invoking the change script.

For me to help with the scripting issue, I would need a screenshot which clearly shows me the line numbers of your script. It's also helpful if you display the script with whitespace so that we can rule out certain issues.

 ![Screenshot 2024-01-22 at 8.54.44 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/5/e56e3a5cff3148946afdd525668b2164f6bfdb45.png)

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 22, 2024, 5:15pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/15 "2024-01-22T17:15:43Z")

</div>

Okay I see.

Here's the screenshot:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/0/80e88a2e34e8fe03dc88cf75517bfdcf559ea589.png)

I even checked my User source to check the username but it's the good one.

Thanks for your help!

---

<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:** [January 22, 2024, 5:22pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/16 "2024-01-22T17:22:26Z")

</div>

Curious. Is this being used in a project which _does_ require authentication? I'm wondering if perhaps it _is_ executing the script on login but perhaps the page it is targeting no longer exists as the session does the unauthenticated -\> authenticated transition?

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 22, 2024, 6:25pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/17 "2024-01-22T18:25:04Z")

</div>

Is it the project property 'Required Client Roles' that you are talking about ? If it's the case it's empty in my project. You can access my project without be logged in, but some functionalities like buttons require you to be logged in to use them.

Also I noticed something, I don't know if it's useful or not, but I tried this by logging in on the main view every times, but in the logs of the gateway in the logs properties of the error, there is a different view for all messages:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/0/10daa9c3e206606a06cd0fe31a6d0b01c2b15cc8.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/0/c00f7b8d7e7d297ad15d724217451171182c5f86.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/5/05d23eb92e5e18d9f69c7b55532d1ed5625b2f9e.png)

After the login screen it's supposed to take me back to the main view so I don't know why the view in the log properties is changing.

---

<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:** [January 22, 2024, 6:51pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/18 "2024-01-22T18:51:32Z")

</div>

I'm referring to this setting here:

 ![Screenshot 2024-01-22 at 10.44.59 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/0/3083532d6b171f2d14d2b0c8d79bc4169989acb7.png)

If `Authenticated` is checked, it means that your project in essence _requires_ that a user be logged in to access the project.

> [@Alexandre\_Pasquereau](#):
>
> there is a different view for all messages:

Are those Views all open in different tabs in your browser? Are they open in the Designer? The `Channel is not set` error has been seen in the past on mobile devices. Where is the session you're using? Are there other sessions in use with this same user?

---

<div class="post-metadata">

**Author:** ![Alexandre\_Pasquereau](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Alexandre\_Pasquereau](https://forum.inductiveautomation.com/u/Alexandre_Pasquereau)\
**Post date:** [January 22, 2024, 6:59pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/19 "2024-01-22T18:59:40Z")

</div>

Oh yes, so my project is Public.

I just tried with my designer closed and only one tab with the main view and still different views in the log properties.  
I'm not using it on a mobile, it's only on computers.  
Some sessions are opened on other computers but none with this user (I can't try to close all the sessions to see if it works as we are currently using the project).

---

<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:** [January 22, 2024, 7:23pm UTC](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442/20 "2024-01-22T19:23:13Z")

</div>

> [@Transistor](#):
>
> `if currentValue != "AP"`

Just a small nit pick, but this will always be true, so is doing nothing but adding unneeded overhead.

The first two checks can be combined into:

```auto
if currentValue and currentValue.value != "AP":
    return

```

I would reduce the code to this:

> **Poorly thought out code**
>
> This text will be hidden
> 
> ```python
> if all([currentValue,currentValue.value == "AP",system.tag.readBlocking(["[default]Test Popup"])[0].value]):
> for index,sessions in enumerate(system.perspective.getSessionInfo()):
> if sessions[index].id != self.props.id:
> continue
> for pID in sessions[index].pageIds:
> system.perspective.openPopup("Test_Popup","Popup/testPopup",modal=True,sessionId=self.props.id,pageId=pID)
> 
> ```

@Alexandre_Pasquereau

Note: That I enumerated the return from `getSessionInfo()` This is because the function returns a _List_ and so will likely not have the properties which the original code expected.

EDIT: It helps if you understand what a function does when you use it. See below for corrected code. No need to enumerate, as this is a list of objects and you're not referencing into the list for any reason. Just use a standard for loop. K.I.S.S.

[Next page](https://forum.inductiveautomation.com/t/system-of-popup-depending-of-the-user/84442.md?page=2)
