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

Dr Atul G- LNG
Tera Patron
Tera Patron

https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-auto-populate-the-logged-in...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

@Dr Atul G- LNG  No need to give wrong solution in hurry. Read my question carefully. I am talking about Rich text label field

My bad.. sorry for this. 

 

Why do you need to pass the logged-in user to the rich text field? Here's a video reference for using a Reference field — see if that approach works for your use case.

 

https://www.youtube.com/watch?v=8jvrvdx5F2Y

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************
Hey all..its been a while!!!...Here we look at how to populate a user reference field on a catalog item variable (in ServiceNow) with the logged in user. We use 2 different approaches to achieve this. The default value in the variable and an onLoad catalog client script. This is all done within an

@Dr Atul G- LNG  I Know how to populate logged in user. I am talking specifically about rich text variable type