In ServiceNow, if you want to display a static content block that is personalized and shows information specific to the current logged-in user, you would typically use a mixture of backend script (e.g., to get user details) and frontend presentation (e.g., HTML or Jelly).
Here's a high-level overview of how you can create a User-Specific Static Content Block in ServiceNow:
- Create a new UI Page or edit an existing one:
Navigate to System UI > UI Pages and click on "New" to create a new UI Page or search for an existing one to edit.
- Use the
GlideUser() API to get the current user's details:
In your UI Page's script section, you can use GlideUser() to obtain details about the current user. For example:
var currentUser = gs.getUser(); // this gets the GlideUser object representing the current user
var userID = currentUser.getID();
var userName = currentUser.getUserName();
var userFullName = currentUser.getFullName();
// Other methods are available to get further details
- Integrate this information into your HTML or Jelly code:
You can then pass these variables to your UI Page HTML or Jelly presentation layer. For example, if using Jelly:
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- Your static content block HTML goes here -->
<div>
<p>Logged in user: ${userFullName}</p>
<!-- Display other information as needed -->
</div>
</j:jelly>
If using HTML in a UI Page or a Service Portal Widget, you may set the variable in a similar manner and include it in your HTML:
<script type="text/javascript">
// You can include the script from above here
</script>
<!-- Your static content block HTML goes here -->
<div>
<p id="user-info"></p>
</div>
<script>
// Using JavaScript to set the inner HTML of the div to include the user's name.
document.getElementById('user-info').innerHTML = 'Logged in user: ' + "${userFullName}";
</script>
- Include the UI Page or Widget in your desired location:
This could be on a dashboard, in a content block, or wherever else it is appropriate for your application.
Note: Static content blocks are often just that: static. They do not typically have the ability to dynamically change their content based on the user viewing them. Therefore, creating a "dynamic" static content block, as described here, involves using UI Pages or Service Portal Widgets instead of simply creating a standard static content record.
Remember, you will need appropriate permissions to create or edit UI Pages and to ensure your scripts maintain best practices for security and user privacy. Always test your changes thoroughly in a non-production instance before deploying to production.