0

Read user variables from plugin script

I've got a client that wants to use their BrightSign XT player to display a sales dashboard.  The website does require a login, which I've been able to execute through a plugin.  However, I'd prefer the store the login credentials (username and password) in User Variables, so it's easier for the client to maintain them. 

However, I have no idea how to do this.  I've tried some different methods, but none seem to work. 

 

Here is the content of the plugin script.

---- START PLUGIN ---

Function sendWebLogin_Initialize(msgPort As Object, userVariables As Object, bsp As Object)
 
  sendWebLogin = newSendWebLogin(msgPort, userVariables, bsp)
  return sendWebLogin
  
End Function  


Function newSendWebLogin(msgPort As Object, userVariables As Object, bsp As Object)  

'create the new object
    
    s={}
    s.objectName = "sendWebLogin_object"
    s.msgPort =   msgPort
    s.userVariables = userVariables
    s.bsp = bsp
    s.htmlwidget = invalid ' We'll use the FindHTMLWidget method to set this later
    s.ProcessEvent =  sendWebLogin_ProcessEvent
    
    return s 
End Function 
    
    
Function sendWebLogin_ProcessEvent(event As Object) as boolean

       m.htmlwidget = FindHTMLWidget(m.bsp) 'find the htmlwidget in the presentation

      'Receive a plugin message
      if type(event) = "roHtmlWidgetEvent" then
        eventData = event.getData()
            if type(eventData) = "roAssociativeArray" and type(eventData.reason) = "roString" then
            print "HELLOOOOOOOOO"
                
                 if eventData.reason = "load-finished" then                   
                    m.htmlwidget.InjectJavaScript("document.getElementById('username').value='my_username';document.getElementById('password').value='my_password';document.getElementById('Login').click();")
                end if
            end if
    end if 
              
    return false 
    
End Function
    
 
Function FindHTMLWidget(bsp)
    for each baZone in bsp.sign.zonesHSM
        if baZone.loadingHtmlWidget <> invalid then
            return baZone.loadingHtmlWidget
        end if
    end for
    print "Couldn't find htmlwidget"
    return false
End Function

--- END PLUGIN

1 comment

  • 0
    Avatar
    Tommy

    I got it working and wanted to share the script.  This script reads three user variables:
    salesforce_username
    salesforce_password
    page_refresh_minutes

    This is for a client that wants to view their salesforce dashboard with auto-login.  Note that we have to add the IP range of the client office to the Salesforce profile under "Trusted Domain" (or something like that) to disable 2FA when you login.

    It will then log them in automatically, and then refresh the page every xx minutes as specified in the last user variable.  If that variable is missing or set to 0, it will not refresh.

    Here's the script:

     

    Function sendWebLogin_Initialize(msgPort As Object, userVariables As Object, bsp As Object)
     
      sendWebLogin = newSendWebLogin(msgPort, userVariables, bsp)
      return sendWebLogin
      
    End Function  


    Function newSendWebLogin(msgPort As Object, userVariables As Object, bsp As Object)  

    'create the new object
        
        s={}
        s.objectName = "sendWebLogin_object"
        s.msgPort =   msgPort
        s.userVariables = userVariables
        s.bsp = bsp
        s.htmlwidget = invalid ' We'll use the FindHTMLWidget method to set this later
        s.ProcessEvent =  sendWebLogin_ProcessEvent
        
        return s 
    End Function 
        
        
    Function sendWebLogin_ProcessEvent(event As Object) as boolean

           m.htmlwidget = FindHTMLWidget(m.bsp) 'find the htmlwidget in the presentation

          'Receive a plugin message
          if type(event) = "roHtmlWidgetEvent" then
            eventData = event.getData()
                if type(eventData) = "roAssociativeArray" and type(eventData.reason) = "roString" then
                    
                     if eventData.reason = "load-finished" then
                     
                         ' Read the user variable with the login username                      
                         if m.userVariables["salesforce_username"] <> invalid
                                 login_username=m.userVariables["salesforce_username"].currentValue$
                         else
                                 login_username="salesforce_username variable undefinded"
                         end if
                         
                         ' Read the user variable with the login password
                         if m.userVariables["salesforce_password"] <> invalid
                                 login_password=m.userVariables["salesforce_password"].currentValue$
                         else
                                 login_password="salesforce_password variable undefinded"
                         end if
                         
                        'print "login_username is " login_username
                       'print "login_password is " login_password
                         
                        ' Build the java command string from the user data
                        javascript_command = "document.getElementById('username').value='" + login_username + "';document.getElementById('password').value='" + login_password + "';document.getElementById('Login').click();"
                        
                        'Inject the script to auto-login
                        m.htmlwidget.InjectJavaScript(javascript_command)

                        ' Read the refresh time (minutes) from the user variables'                    
                         if m.userVariables["page_refresh_minutes"] <> invalid
                                 refresh_string=m.userVariables["page_refresh_minutes"].currentValue$
                                 refresh_int = refresh_string.ToInt() * 60000
                         else
                                 refresh_int = 0
                         end if                                     
                         
                        if (refresh_int > 1000)
                            ' Build the javascript command to refresh the page
                            javascript_command = "window.setInterval('refresh()', " + refresh_int.ToStr() + ");function refresh() { window.location.reload();}"
                            
                            ' Inject a script to refresh the page every xx seconds
                            m.htmlwidget.InjectJavaScript(javascript_command)
                        end if
                        
                    end if
                end if
        end if 
                  
        return false 
        
    End Function
        
     
    Function FindHTMLWidget(bsp)
        for each baZone in bsp.sign.zonesHSM
            if baZone.loadingHtmlWidget <> invalid then
                return baZone.loadingHtmlWidget
            end if
        end for
        print "Couldn't find htmlwidget"
        return false
    End Function

Please sign in to leave a comment.