How to populate field message on top of the field using client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi All,
I'm writing a catalog client script to populate a field message using g_form.showFieldMsg() method. This method displays a message under the specified form field but the requirement is to show on top of the field,
How to populate a field message on top of the field using client script?
g_form.showFieldMsg('impact','Low impact response time can be one week','info');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
it will always come at the bottom and not on top of the field
That's OOTB behavior of showFieldMsg() method
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
if you want to show static text all the time above the field then
1) either use hint but user will have to click and then see the text
OR
2) use form annotation and add text above that field.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hello @The Matrix ,
it does not show above the field !
it always show below the field..
Refer this :
I want to display a field message.
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @The Matrix
To show a message directly on top of a field, you cannot use g_form.showFieldMsg(). Instead, you must use one of the four alternative approaches detailed below.
Option 1 : Refer :KB0675031 The "showFieldMsg()" method does not display messages for "label" type fields in Service P...
Workaround
This is expected behaviour in the current Service Portal design. This issue has been identified as a possible future product enhancement. As a workaround, reference the last variable under the label one in the showFieldMsg() method, rather than the label variable itself.
Option 2: Create a dedicated Custom / Rich Text or Label variable positioned directly above your input field. You can leave it hidden by default and toggle its visibility using a Catalog UI Policy or a Client Script.
- Create a Rich Text variable right above your input variable. Set its value to your message.
- Use a Catalog UI Policy to show/hide it based on your field's value.
Sample code //change it as per your requirement
if (newValue == 'trigger_value') {
g_form.setVisible('your_rich_text_variable_above', true);
} else {
g_form.setVisible('your_rich_text_variable_above', false);
}
Option 3:
If the exact placement above the specific field is negotiable, the standard ServiceNow approach is to display a form-level message at the very top of the entire Catalog Item form using g_form.addInfoMessage() or g_form.addErrorMessage()
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti