Display Logged in User Name in "Rich Text label" Html variable on Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 06:30 PM
Hello Everyone,
I want to display logged in user name on the Catalog item, saying "Welcome Username". I want to use HTML to achieve this.
So, I have created a Rich Text Variable on the catalog item and in its source code i tried below codes but none worked.
Please can anyone help me achieve this.
Regards,
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 06:55 PM
Unfortunately the Rich Text Label and other HTML fields do not permit scripting and you can't dynamically set the content (setValue is not supported).
You could do this with a Macro type variable and Service Portal widget.
HTML:
<div>
<p>Welcome {{data.user_name}}</p>
</div>
Server Script
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.user_name = gs.getUserDisplayName();
})();
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-01-2021 04:56 AM
Thank you Michael, it is interesting.
Would it be possible to have some more detailed instructions for newbies like me, on how to get a text which reads like this in a record producer:
You identified as Flavio Costa
where "Flavio Costa" is the name of the currently logged in user?
I understand that a Macro type variable should be used in the, with a definition of a Macro and a Widget in the Type Specifications tab.
What exactly should be entered in the XML field of the Macro and in the 'Body HTML template' field of the Widget or whatever else?
Thanks in advance
Flavio

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-01-2021 06:05 AM
Certainly;
Step 1: Create your Widget
Go to Service Portal > Widgets
Click New
Name: Show Name
Check the box for Public
HTML Template:
<div>
<p>You identified as {{data.user_name}}</p>
</div>
CSS:
Nothing needed here specifically but you could define styles here.
Server script:
(function() {
//Create the data object and push the display name of the logged in user to data.user_name
data.user_name = gs.getUserDisplayName();
})();
Submit.
Step 2: Add a variable to your Catalog Item
Open your catalog item
Under Variables click New
Select a Type of Macro (Paris or earlier) or Custom (Rome or later)
Question / Name: Greeting
Order: As you like
Under Type Specifications / Widget: Select the widget you created (Show Name)
Submit.
Load your catalog item in the Portal:
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-01-2021 06:45 AM
Thanks! In my previous attempt I was not setting the function in the right place (Server script).
Hope I marked the answer appropriately.