- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:25 AM
I have a rich text label field. I have to populate the logged in user in this field. Its urgent anybody could help?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:52 AM
Hello @garimakharb ,
The functionality you're looking for—populating the logged-in user's name in a Rich Text Label—is not directly possible. Rich Text Label variables in Service Catalog don't support scripting or dynamic updates, so you can't inject something like the user's display name into them using setValue() or similar methods.
However, there is a workaround using a Custom type variable with a Service Portal widget. This allows you to display dynamic text, like showing a welcome message with the current user's name.
Here’s how you can do it:
Step 1: Create a custom widget
-
Navigate to Service Portal > Widgets and click "New".
-
Give it a name like “Display User Greeting”.
-
In the HTML Template field, add:
<div>
<p>Welcome, {{data.user_name}}</p>
</div>
4 . In the Server Script field, add:
(function() {
data.user_name = gs.getUserDisplayName();
})();
5. Submit the widget.
Step 2: Add a Macro or Custom variable to your catalog item
-
Open your catalog item or record producer.
-
Under Variables, click New.
-
Set the Type as “Custom”.
-
In the Type Specifications, choose the widget you just created.
-
Fill out the rest of the details as needed and save.
Now when the item loads in the portal, the user should see a greeting message with their name.
This approach was also discussed in another thread by Michael Jones where he shared a similar solution. It matches your use case quite well, so I’d recommend checking that out too for more clarity.
Let me know if this helps.......
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:45 AM
Hi @garimakharb
Risch text label field is nothing but a HTML field.
So, create on_load client script and use GlideUser class to fetch the basic info like First name, Full name, Last name, User ID, User name.
To get other infos like manager, department etc, then create client callable script include and use it in your client script.
Review this approach and let me know if you have any queiries..
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:46 AM
@J Siva Can you provide my the OnLoad client script? which can actually work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:54 AM - edited 08-01-2025 03:59 AM
@garimakharb Please note that this will work only in the service portal but not in the classic view.
We are using this and it's working fine without any issues in the service portal.
var first_name = "<p> First Name: "+g_user.firstName+"</p>";
g_form.setLabelOf("<rich_text_variable_name>",first_name );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:52 AM - edited 08-01-2025 03:52 AM
Hello @garimakharb ,
I think there is scripting limitation for Rich Text Label type of field.
Instead you might have to use macro as suggested as a workaround (in below thread).
Check this thread , as similar thing is discussed here.
I hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:52 AM
Hello @garimakharb ,
The functionality you're looking for—populating the logged-in user's name in a Rich Text Label—is not directly possible. Rich Text Label variables in Service Catalog don't support scripting or dynamic updates, so you can't inject something like the user's display name into them using setValue() or similar methods.
However, there is a workaround using a Custom type variable with a Service Portal widget. This allows you to display dynamic text, like showing a welcome message with the current user's name.
Here’s how you can do it:
Step 1: Create a custom widget
-
Navigate to Service Portal > Widgets and click "New".
-
Give it a name like “Display User Greeting”.
-
In the HTML Template field, add:
<div>
<p>Welcome, {{data.user_name}}</p>
</div>
4 . In the Server Script field, add:
(function() {
data.user_name = gs.getUserDisplayName();
})();
5. Submit the widget.
Step 2: Add a Macro or Custom variable to your catalog item
-
Open your catalog item or record producer.
-
Under Variables, click New.
-
Set the Type as “Custom”.
-
In the Type Specifications, choose the widget you just created.
-
Fill out the rest of the details as needed and save.
Now when the item loads in the portal, the user should see a greeting message with their name.
This approach was also discussed in another thread by Michael Jones where he shared a similar solution. It matches your use case quite well, so I’d recommend checking that out too for more clarity.
Let me know if this helps.......
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024