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 07:48 PM
why are you using DOM manipulation?
why not use g_form.addInfoMessage()
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 08:21 PM
Hi,
I am not able to achieve the following,
- The label should have white text on a red background.
- "Stage" field label should also be highlighted in red.
- Also red dot flagging in list views
Client script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 09:12 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:13 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