Select to view content in your preferred language

Retrieve the username of the person connected on the Experience Builder Application

4870
17
Jump to solution
10-12-2023 05:50 AM
JasonBOCQUET
Frequent Contributor

Hello community,

 

I am currently building an ArcGIS Experience Builder application and I would like to be able to add a header where the person viewing the application with a connected ArcGIS account can see a message like "Hello, Franck". But I don't know how to get the user's first name or nickname and how to integrate it into a Text widget or elsewhere.

Can you help me ?

 

Have a nice day.

0 Kudos
17 Replies
JeffreyThompson2
MVP Frequent Contributor

It might be as simple as adding a question mark to this line.

<div className='center'>
{props.user?.firstName &&
	 <span><p>Bonjour {props.user.firstName}</p></span>
	 }
	</div>

You could also try a teriary.

<div className='center'>
{props.user ? 
	 <span><p>Bonjour {props.user.firstName}</p></span> : <></>
	 }
	</div>

The next thing to try after that is to use your useEffect statement to put the username into state.

GIS Developer
City of Arlington, Texas
0 Kudos
JasonBOCQUET
Frequent Contributor

Hi @JeffreyThompson2 it works with your first advice, big thanks 🙂

0 Kudos
JasonBOCQUET
Frequent Contributor

Hello !

 

Can I create a little script for this widget (which be simple to write) without using the developer edition ?

 

I mean, i can't host the application on a webserver because i have not the right. I only want to import a little script to have a custom widget.

 

Thanks.

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

There is no way to simply add a few lines of code to Experience Builder without Developer Edition. If you are using a version of ArcGIS Enterprise 11.X, it is possible to connect a custom widget to your portal, but you will still need to host the custom widget on the web somewhere. https://www.esri.com/arcgis-blog/products/arcgis-enterprise/developers/add-experience-builder-custom...

This example hosts the widget on Github Pages which is a simple, free hosting platform for very basic applications.

GIS Developer
City of Arlington, Texas
JasonBOCQUET
Frequent Contributor

Oh ! it's gonna be good for me ! Nice !

 

So if I want to write a javascript for a custom widget to retrieve the username, i have only to use the props.user objects or it's more complicated ? I'm not friendly with javascript.

 

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

https://developers.arcgis.com/experience-builder/guide/install-guide/

https://developers.arcgis.com/experience-builder/guide/create-a-starter-widget/

https://docs.github.com/en/get-started/quickstart/set-up-git

Before getting started read over the installation and starter widget guides. You should also look at the GitHub guides if you are going to host there. There is a steep learning curve in the setup process if you are not familiar with programming.

GIS Developer
City of Arlington, Texas
JasonBOCQUET
Frequent Contributor

Thanks for the links.

I'm gonna read all of this and try to create the widget after that. U help me very well thank you.

0 Kudos
Marc_Graham
Frequent Contributor

Just as an update for anyone looking for this post 2025: you can do this with smart forms and Arcade.

https://developers.arcgis.com/arcade/function-reference/portal_functions/

Marc_Graham_0-1753137620603.png