Service catalog

garimakharb
Mega Guru

I have a rich text label field.  I have to populate the logged in user in this field. Its urgent anybody could help?

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

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

  1. Navigate to Service Portal > Widgets and click "New".

  2. Give it a name like “Display User Greeting”.

  3. 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

  1. Open your catalog item or record producer.

  2. Under Variables, click New.

  3. Set the Type as “Custom”.

  4. In the Type Specifications, choose the widget you just created.

  5. 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

View solution in original post

10 REPLIES 10

J Siva
Tera Sage

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

garimakharb
Mega Guru

@J Siva Can you provide my the OnLoad client script? which can actually work?

@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 );

 

Ct111
Giga Sage

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

Aniket Chavan
Tera Sage
Tera Sage

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

  1. Navigate to Service Portal > Widgets and click "New".

  2. Give it a name like “Display User Greeting”.

  3. 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

  1. Open your catalog item or record producer.

  2. Under Variables, click New.

  3. Set the Type as “Custom”.

  4. In the Type Specifications, choose the widget you just created.

  5. 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