HTML Client Script for Displaying Caution Label in RITM Form - Need Help"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 07:45 PM
Hi,
I’m trying to display a caution label at the top of an RITM form when the "Stage" field value is set to "waiting_for_approval". The goal is to ensure that the label appears at the top of the form so that users don’t accidentally fulfill or handle tickets that are not yet approved.
Requirements:
- Display a warning message at the top of the RITM form when the "Stage" field has the value "waiting_for_approval".
- Label content:
CAUTION
"Ticket is awaiting approval per defined flow. Do NOT fulfill/handle unless manual approval has been achieved." - The label should have white text on a red background.
- "Stage" field label should also be highlighted in red.
- The label should only be shown when the "Stage" value is "Waiting for Approval"
- Also red dot flagging in list views
Issues I’ve Encountered: I tried using .body and .polaris as possible selectors for the form’s main content, but I still don't see the label.
Client Script:
function onLoad() {
var stage = g_form.getValue('stage');
if (stage == 'waiting_for_approval') { // Assuming internal value for "Waiting for Approval" is '1'
// Create and display the caution label at the top of the form
var cautionLabel = document.createElement('div');
cautionLabel.id = 'caution-label';
cautionLabel.style.backgroundColor = 'red';
cautionLabel.style.color = 'white';
cautionLabel.style.textAlign = 'center';
cautionLabel.style.padding = '10px';
cautionLabel.style.fontWeight = 'bold';
cautionLabel.innerText = 'CAUTION: Ticket is awaiting approval. Do NOT fulfill/handle unless approved manually!';
// Insert caution label at the top of the form's body section
var formBody = document.querySelector('.body');
if (formBody) {
formBody.insertBefore(cautionLabel, formBody.firstChild);
}
// Highlight the STAGE field label with a red background
var stageLabel = document.querySelector('label[for="stage"]');
if (stageLabel) {
stageLabel.style.backgroundColor = 'red';
stageLabel.style.color = 'white';
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 09:15 PM
Hello @Service now11,
Can you try by using getDisplayBox
g_form.getDisplayBox('fieldname'). style == 'red';
If my response helped, please mark it correct and close the thread so that it benefits future readers.
Shruti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 09:15 PM
you can give HTML tags to info messages using g_form
Is getControl() not working in your script?
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-21-2025 01:23 AM
Hope you are doing good.
Did my reply answer your question?
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-26-2025 12:43 AM
Hope you are doing good.
Did my reply answer your question?
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:29 PM - edited 02-16-2025 10:30 PM
Hello, I think the requirement should be redesigned as it creates bad user experience. Some random red label doesn't stop users to edit the record. Try instead:
- Make fields read only by Client Script, should be protected also from server side by before Business Rules aborting submit if values were modified
OR - Record level write ACL with condition Stage = wait_for_approval returning false (or use type 'Deny unless' Stage != wait_for_approval
If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin