How to get Current User on Start Page
Moderator: Phil Barton
How to get Current User on Start Page
I am attempting to create a custom Start Page, and I would like to access the current username. I followed the directions previously posted here: https://devforum.softprocorp.com/viewto ... ?f=6&t=310. Unfortunately, the javascript statement 'var myautomation = window.external.GetObject("MyAutomation")' returns an exception 'window.external.GetObject is not a function'. I enumerated the members in window.external and found only AddSearchProvider, & IsSearchProviderInstalled. After consulting the SelectDefaultStartPage.html, I noticed references to EnvICE that seems to support some of the functionality that windows.external previously provided. Enumerating the members of EnvICE, I found showContextMenu, getRecentDocuments, execCmd, equals, getHashCode, & toString - but no getObject. Is it still possible to access the current username from a custom start page? And, if so, how is it done? We are currently running version 4.3.60210.119 of Select. Thx.
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: How to get Current User on Start Page
Sorry for the issues. I have passed this on to R&D. I will return any information they provide.
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: How to get Current User on Start Page
R&D has responded that there is no direct way to do what you are asking.
Their only recommendation is for you to create a custom shell package that provides an extended start page object with the property you need. An (untested) example class was provided by them:
In the shell package initialization, you must register the new class with the IStartPageProvider:
Finally, your start page you would get the new property.
Their only recommendation is for you to create a custom shell package that provides an extended start page object with the property you need. An (untested) example class was provided by them:
Code: Select all
using SoftPro.Select.Controls;
internal class SessionExtensibilityObject : IHtmlBrowser2ExtensibilityObject
{
private IServiceProvider _site;
private HtmlBrowser2 _browser;
public SessionExtensibilityObject(IServiceProvider site)
{
_site = site;
SelectServer sps = _site.GetService<SelectServer>();
this.UserName = sps.AuthenticatedUserName
}
void IHtmlBrowser2ExtensibilityObject.Initialize(HtmlBrowser2 browser)
{
_browser = browser;
}
public string UserName {get; private set;}
}
Code: Select all
var spp = GetService<IStartPageProvider>();
spp.Register("Session", () => new SessionExtensibilityObject(this));
Code: Select all
var name = Session.UserName
Bob Richards, Senior Software Developer, SoftPro
Re: How to get Current User on Start Page
Bob,
Thx for the reply. I tried the example class you provided, and would like to relate my experience/discoveries for any other viewers.
The sample code creates a browser extension called Session which exposes an property called UserName. I found that the property was not visible to the javascript code. However, when I changed it to a public method, it was visible to the start page javascript. So, something like the following worked:
On the javascript side, the call to the method returns a Promise. So, to access the values, I used something like this:
And it is possible to return multiple values from the extension method using an anonymous object or a Dictionary. Thx again for your assistance.
Thx for the reply. I tried the example class you provided, and would like to relate my experience/discoveries for any other viewers.
The sample code creates a browser extension called Session which exposes an property called UserName. I found that the property was not visible to the javascript code. However, when I changed it to a public method, it was visible to the start page javascript. So, something like the following worked:
Code: Select all
internal class SessionExtensibilityObject : IHtmlBrowser2ExtensibilityObject
{
private IServiceProvider _site;
private HtmlBrowser2 _browser;
private string userName;
public SessionExtensibilityObject(IServiceProvider site)
{
_site = site;
SelectServer sps = (SelectServer)_site.GetService(typeof(SelectServer));
userName = sps.AuthenticatedUserName;
}
void IHtmlBrowser2ExtensibilityObject.Initialize(HtmlBrowser2 browser)
{
_browser = browser;
}
public string GetUserName() => userName;
}
Code: Select all
function getUserName() {
try {
Session.getUserName().then( // Call the Session extension - then handle the result
function (value) { display(value); }, // do something with the returned data
function (error) { alert('error:' + error); } // ... or, report the error
);
}
catch (err) {
alert(err.message);
}
}
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: How to get Current User on Start Page
Thank you so much for providing the follow up for your solution. We appreciate that you shared your time and effort with others on the DevForum!
Bob Richards, Senior Software Developer, SoftPro