I'm building a custom widget in WAB. I need to retrieve the user name of the user logged into the Portal. Is there a property or function in WAB somewhere that can provide that?
Solved! Go to Solution.
Hi Ben,
You can define portalUtils in widget and access user through the portal instance:
define([ 'jimu/BaseWidget', 'jimu/portalUtils', 'dojo/_base/declare' ], function(BaseWidget, portalUtils, declare) { ... this.portal = portalUtils.getPortal(this.appConfig.portalUrl); username = this.portal.user.username; ...
See also:
https://developers.arcgis.com/javascript/jsapi/portal.html
https://developers.arcgis.com/javascript/jsapi/portaluser-amd.html
Hi Ben,
You can define portalUtils in widget and access user through the portal instance:
define([ 'jimu/BaseWidget', 'jimu/portalUtils', 'dojo/_base/declare' ], function(BaseWidget, portalUtils, declare) { ... this.portal = portalUtils.getPortal(this.appConfig.portalUrl); username = this.portal.user.username; ...
See also:
https://developers.arcgis.com/javascript/jsapi/portal.html
https://developers.arcgis.com/javascript/jsapi/portaluser-amd.html
Thank you Herdis.
I hadn't found the portalUtils.getPortal() function. That is what I needed to get a reference to the portal instance the WAB is using.
I wish WAB was better documented.
Does this work for in-panel widgets?
I am getting a: " Uncaught TypeError: Cannot read property 'portalUrl' of undefined " error when I use this code. When I don't have this code, my template loads correctly without any errors and I do have the correct portalUrl in place??
did you ever figure this out? having the same issue. sometimes i think people find it funny to post incomplete examples instead or withhold which version of the api they are using.
I can't say how much has changed in five years - but I suggest you to debug it by looking into the properties of 'this' in this.appConfig.portalUrl - since the error message implies that appConfig is null - maybe this has changed since 2015? Or maybe the 'this' in your script point to something else? Anyway, good luck.