I want to get the portal user and their associated groups when the map loads in Web app builder. In the previous version of WAB there was function getUserGroups to get the portal user group names. I am not able to find a similar function in the latest WAB. Has anyone tried to get Groups of portal user? Any suggestions is greatly appreciated.
Thanks,
RB
I still get the same issue with portalUrl. I am writing my code in WidgetManager.js. It contains the required imports for portalUtils in the define and function sections. I still get the same error even if I model my code similar to (using portalUtils to get current logged user won't work for off-panel widgets ) This is my current code (modeled after https://community.esri.com/message/555547?commentID=555547#comment-555547) :
var func = lang.hitch(this, function(){
this.portal = portalUtils.getPortal(this.appConfig.portalUrl);
var username = this.portal.username;
console.log(username);
});
func();
........
This code is written right before the last return statement in WidgetManager.js. I get the portalUrl error even if I place the code in a widget such as WMXLegend/Widget.js.
Mansi,
Sounds like a scope issue. You need to use lang.hitch to maintain your code blocks scope.
I'm not sure why I keep getting a portalUrl not defined issue even though I have the correct portalUrl in my WAB template's config file? I keep getting this error whether I use code in this thread or if I use code in the following thread: https://community.esri.com/message/740450-re-how-can-i-retrieve-the-portal-user-name-in-a-custom-wab-widget?commentID=74…
Sounds like a timing issue. Have to tried to use a setTimeout for a couple of seconds and see if that works?
Thanks for the quick reply Robert. But when i try this inside the LayoutManager.js _onMapLoaded function, it throws an error stating "Credential is null"
RB,
You would use the portalUtils class in jimu:
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="string token">'jimu/portalUtils'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'jimu/portalUrlUtils'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> portalUtils<SPAN class="punctuation token">,</SPAN> portalUrlUtils<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">var</SPAN> portalUrl <SPAN class="operator token">=</SPAN> portalUrlUtils<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getStandardPortalUrl</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>appConfig<SPAN class="punctuation token">.</SPAN>portalUrl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> portal <SPAN class="operator token">=</SPAN> portalUtils<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getPortal</SPAN><SPAN class="punctuation token">(</SPAN>portalUrl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> portal<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getUser</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN>lang<SPAN class="punctuation token">.</SPAN><SPAN class="token function">hitch</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>user<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>portalUser <SPAN class="operator token">=</SPAN> user<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.