g_form.showFieldMsg() Disappears After Field Value Selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
We are using an onChange Client Script to display a g_form.showFieldMsg() message when certain conditions are met. The message is displayed correctly initially. However, once the user enters/selects a value in the field, the field message disappears automatically.
Our requirement is for the message to remain visible at all times as a dynamic hint whenever the condition is satisfied, even after the field value is selected or modified. Since a standard dynamic hint is not available for this use case, we are trying to use showFieldMsg().
Could you please advise:
- Is this expected behavior of g_form.showFieldMsg()?
- Is there a recommended approach to keep the message persistently visible while the condition remains true?
- Are there any alternative solutions that can behave like a dynamic hint on the form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @PoojithaHasthi ,
Refer this client script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var fieldName = 'u_incident';
var placeholder = "##placeholder##"
if (isLoading || newValue === '') {
g_form.showFieldMsg(fieldName, placeholder, 'info');
return;
}
g_form.hideFieldMsg('fieldName', true);
g_form.showFieldMsg(fieldName, placeholder, 'info');
//Type appropriate comment here, and begin script below
}
If this helps you then mark it as helpful and accept as solution.
Regards,
Aditya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
In our implementation, the message is shown when:
- Policy = FJ-GDSL-GD Security Policy (87bfefaa1bdb1150b3891065bb4bcb39)
- Control Objective includes FJ-SECPL-AUP-02 (e7eafe5233fbba9412deaf5c2d5c7ba9)
However, when the condition matches, the message is displayed initially but disappears once the user clicks into or updates the Valid To field. Even if Valid To remains empty and the condition is still true, the message does not reappear.
Our expectation is that the message should remain visible as long as the Policy and Control Objective condition is satisfied. Is this expected behavior of showFieldMsg(), or is there a recommended OOB approach for a persistent field-level hint/message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
My thoughts
-> yes this is standard OOTB behavior
-> Why not use Form annotation and show a text just above or below that field which guides user about the message
-> Another approach is to below
a) keep existing onChange as it is and no change
b) Create another onChange on valid_to and add script and validation there also
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) return;
var fieldName = 'valid_to';
// Re-evaluate the same condition you use in the other onChange
var policy = g_form.getValue('policy');
var controlObjectives = g_form.getValue('control_objectives') || '';
var match = (policy === '87bfefaa1bdb1150b3891065bb4bcb39' &&
controlObjectives.split(',').indexOf('e7eafe5233fbba9412deaf5c2d5c7ba9') > -1);
// Always hide first to avoid duplicates
g_form.hideFieldMsg(fieldName, true);
if (match) {
g_form.showFieldMsg(
fieldName,
'Use the GitHub Copilot license expiry date if it occurs before the maximum exception duration; otherwise use the maximum exception duration end date.',
'warning'
);
}
}
💡 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
25m ago
Hi @Ankur Bawiskar and @Aditya_hublikar ,
I also tried creating a separate onChange Client Script on the Valid To field as suggested, but the behavior remains the same. When the Policy is FJ-GDSL-GD Security Policy and the Control Objective includes FJ-SECPL-AUP-02, the message is displayed initially. However, once I select or update a value in the Valid To field, the message disappears.
Even if the condition still matches and the field is subsequently cleared/left empty, the message does not reappear automatically. Our expectation is that the message should remain visible at all times while the condition is satisfied.
Could you please confirm if this is the expected OOTB behavior of g_form.showFieldMsg() or recommend an alternative approach for a persistent field-level hint/message?
