How to set dynamic data in UI message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 07:39 PM - edited 02-16-2025 07:40 PM
my requirement is to show the message The article <article number> has been retired. when article is retired but currently its showing Knowledge record not found
in the knowledge content widget there is this part in server script
else{
data.messages.INSUFFICIENT_PREVILEGES = gs.getMessage("You do not have sufficient privileges to access this knowledge item");
data.messages.RECORD_NOT_FOUND = gs.getMessage("Knowledge record not found");
}
i replace the 'Knowledge record not found' by using system ui messages key = 'Knowledge record not found' and message 'The article {0} has been retired' but {0} should be dynamic showing the current knowledge article number
How to do this without modifying the widget server script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 09:30 PM
try this and see if it works
else{
data.messages.INSUFFICIENT_PREVILEGES = gs.getMessage("You do not have sufficient privileges to access this knowledge item");
data.messages.RECORD_NOT_FOUND = gs.getMessage("The article <a href={0}>{1}</a> has been retired");
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 10:08 PM - edited 02-16-2025 10:12 PM
Hello,
try to replace row 200 (as is in your image) in your server script with this code:
data.messages.RECORD_NOT_FOUND = gs.getMessage("article.retired.message", knowledgeRecord.number);
As I understand from row 195, you have knowledgeRecord object populated so it should has also number.
Next make sure you have created new record in Messages table [sys_ui_message]:
Key: article.retired.message
Language: English
Message: The article {0} has been retired.
Official ServiceNow documentation: GlideSystem | getMessage(String messageID, Object args)
If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 10:12 PM
Hi @Martin Friedel ,
I cant edit the server script as its OOTB widget & requirement is not to clone this widget as well hence my ask is how to update without modifying the widget server script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 10:19 PM
Unfortunately I believe it is not possible without customizing the widget as you need to pass article number dynamically from widget to UI message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 06:12 PM
Hello @joyceelynn
To meet your requirement, you need to modify line 200 in the server script:
data.messages.RECORD_NOT_FOUND = gs.getMessage("The article {0} has been retired", [knowledgeRecord.number]);
- Here, {0} dynamically retrieves the article number from the second parameter: [knowledgeRecord.number].
- The second parameter must be an array, where {0} will automatically reference the first element, ensuring the message renders dynamically with the correct article number.
To learn more about the second parameter refer to the article: gs.getMessage() - The Second Parameter
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar