Pass data from Vision to Perspective via Web Browser

Hey Everyone!

Somebody can advice me how to send parameters from Vision to Perspective?

I have a Tree View in Vision. So when I select item from Vision Tree View, I have to send radius for map marker.

I tried system.net.httpPut(), but it doesn’t work…

You could either do one of two things:

  1. Perspective can take parameters in the URL after the page name. If you set the page name to something like /pagename/:param1 then if you go to a url ending in /pagename/25 the main view will be provided a parameter named param1 that equals 25. You can chain these along for more parameters too, but this doesn’t allow you to send anything from Perspective back to Vision. This also means for a parameter change it would need to reload the perspective page (not ideal)
  2. Creating a link between the Vision and Perspective clients through the perspective sessionid/pageid and using project scripts to send perspective messages to the page. Then on the perspective page you would have a session scoped messagehandler on the map component, that would take whatever payload and add the radius. In your project Script run a ‘system.perspective.getSessionInfo()’ and then Iterate that JSON to see if there is anything you could identify that session with. If not, you could pass a parameter through the url like a “Vision sync ID”, then make your messageHandler call go to all sessions, by iterating through that JSON, and you would only handle it on the sessions where that sync ID that you give it matches the parameter on the page.

I think that option 2 is your best bet, and if you think you need anymore clarification let me know, I’m sure I could mock something up

1 Like

Thanx for Your reply!

Yes You’re right. and yes when I try to put parameter via URL, then the page reloads…

I use link with ClientID.

deal! :slightly_smiling_face:

Just updated the above with the remainder of the 2nd option

Let me know if you need a bit of a more clear write up, I can give examples and all

1 Like

yes please!!

  1. Create a Perspective page url with a ClientID parameter as follows:
    image
  2. Then create a view parameter with the same name on your view:
    image
  3. I binding mine to a text box for visibility:
  4. Create a messageHandler on a Perspective component, that will be used to recieve the data from vision. In my case I made it a simplelabel, that will receive the data and put it in the text property. Note that it is session scoped.
#Check to make sure that the call is coming from the same Vision Client
#The URL implicitly converts numbers to a string, so its best to cast it that way for comparison
if str(payload['ClientID']) == str(self.view.params.ClientID):
    self.props.text = payload['SentText']
  1. Set the gateway scripting project to the name of your project, so that the gateway knows where the upcoming Gateway Message Handler is located

  2. Create a gateway message handler that looks through each session, and sends the message to each.

	clientId = payload['ClientID']
	text = payload['Text']
	
	#Define your message payload
	payloadDict = {"ClientID":clientId, "SentText":text}
	
	#Gather all perspective sessions
	sessionList = system.perspective.getSessionInfo()
	
	#For each perspective session
	for session in sessionList:
		#Ignore the designer
		if session['userAgent'] != "<designer>":
			#Grab your SessionID
			sessionId = session['id']
			#Look at all open pages
			for page in session['pageIds']:
				system.perspective.sendMessage(messageType="RecieveVisionData", scope="session", payload=payloadDict, sessionId=sessionId, pageId=page)			
  1. Create a project script that will give you your Vision Client ID (To put it in a binding later on)
def getClientID():
	return str(system.util.getClientId())
  1. Create an expression binding on your web browsers URL to navigate to the correct perspective session, and append your client ID to the end of the URL
"http://localhost/data/perspective/client/Vision_To_Perspective_Sync/Test/" + runScript("PerspectiveSync.getClientID()")
  1. Create a button and text field component, to create some data and trigger a call to the perspective session with the following script:
clientID = system.util.getClientId()
text = event.source.parent.getComponent('Text Field').text
payloadDict = {"ClientID":clientID, "Text":text}
system.util.sendMessage(project="Vision_To_Perspective_Sync", messageHandler="PerspectiveMessage", payload=payloadDict)
  1. Open a vision client, type some text in, and watch it appear in perspective!

You can scale this as needed for your project with the map radius, the only critical item being passed around here is the ClientID. If you are using authentication in perspective, you could also probably make this a bit more efficient by passing the gateway event a username, and filtering the system.perspective.getSessionInfo() with a username parameter.

This was an interesting little challenge, originally I mentioned using a project script but I was unaware that scripts called there execute in the scope of the originator. Meaning that because we’d be calling it from a Vision client, than it would execute in the Vision Client scope and wouldn’t have access to any of the system.perspective functions needed. That is why I switched to a gateway event handler.

Here is an export of the project as well, if that works out for you let me know, and I will go ahead and put it on the exchange for others as well.
Vision_To_Perspective_Sync_20200616083646.zip (17.8 KB)

3 Likes

As a note on the above, @PGriffith do you know if project scripts executed from vision will ever be able to execute the system.perspective functions? Or would this essentially be the same level of effort as making them vision scoped scripts as well? The use of gateway event handlers here makes this “a bit more hidden” than I think it should need to be, as opposed to just putting it in a project event script would allow it to work with perspective embedded in both vision and other perspective pages.

I seriously doubt vision will ever be able to execute system.perspective functions – they are system.perspective because they are unique to perspective’s technology.

3 Likes

I think generally speaking we’re encouraging the decision of Vision or Perspective, not Vision and Perspective. It’s sometimes necessary as a transition, but in an ideal world you’ll only end up using one or the other long term.

1 Like

I am working on it now… but seems like it will not work. Anyway I’ll let You know :ok_hand:

Yeah I’m curious, I tried doing it as a fresh install of a project and it worked for me? So I’m curious what’s missing

I think you may need to set the global scripting project in order for this to work. I tried uploading it to a new gateway instead of my original one and that was the fix it needed.

I also updated the instructions for anyone else looking at this

1 Like

5 posts were split to a new topic: Open link in browser via scripting