- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi All,
We have a requirement to add a placeholder text to the work notes field in the incident records. It is possible to add a placeholder text to any new record before submitting it. However, unfortunately, in case of already existing incidents the placeholder text flashes for a second and then disappears. Could anyone advice on what could be modified in the below onLoad Client Script?
function onLoad() {
var placeholderText = "This is a placeholder text";
var workNotes = g_form.getControl("work_notes");
var streamNotes = g_form.getControl("activity-stream-work_notes-textarea");
// If this is a *new* incident
if (g_form.isNewRecord()) {
if (workNotes) {
workNotes.placeholder = placeholderText;
}
}
// If this is an *existing* incident
else {
if (streamNotes) {
streamNotes.placeholder = placeholderText;
}
}
}
I would be grateful for any hints, or suggestions!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
by giving timeout of 2 seconds it worked for me in new and existing record both
function onLoad() {
setTimeout(function() {
var placeholderText = "This is a placeholder text";
var workNotes = g_form.getControl("work_notes");
var streamNotes = g_form.getControl("activity-stream-work_notes-textarea");
// If this is a *new* incident
if (g_form.isNewRecord()) {
if (workNotes) {
workNotes.placeholder = placeholderText;
}
}
// If this is an *existing* incident
else {
if (streamNotes) {
streamNotes.placeholder = placeholderText;
}
}
}, 2000);
}
Output:
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
7 hours ago
Hi @kandulek
Instead of a fixed timeout, you can use a retry loop to check until the element exists:
function setStreamPlaceholder(text) {
var streamNotes = document.querySelector("textarea#activity-stream-work_notes-textarea");
if (streamNotes) {
streamNotes.setAttribute("placeholder", text);
} else {
setTimeout(function() {
setStreamPlaceholder(text);
}, 300);
}
}
function onLoad() {
var placeholderText = "This is a placeholder text";
if (g_form.isNewRecord()) {
var workNotes = g_form.getControl("work_notes");
if (workNotes) {
workNotes.placeholder = placeholderText;
}
} else {
setStreamPlaceholder(placeholderText);
}
}
This ensures the placeholder stays even after the activity stream replaces the textarea.
Note: This only works in UI16/UI15. If you’re using UI Builder / Workspace, you’ll need a different approach (client extension point in the workspace component).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Hi Rafael,
Thank you for a quick reply.
Just tested your solution but unfortunately work notes still don't display my placeholder text. We use UI16.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
any other client script is adding that placeholder?
did you try to add some timeout for 2-3 seconds and see if your script is able to set that?
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
6 hours ago
by giving timeout of 2 seconds it worked for me in new and existing record both
function onLoad() {
setTimeout(function() {
var placeholderText = "This is a placeholder text";
var workNotes = g_form.getControl("work_notes");
var streamNotes = g_form.getControl("activity-stream-work_notes-textarea");
// If this is a *new* incident
if (g_form.isNewRecord()) {
if (workNotes) {
workNotes.placeholder = placeholderText;
}
}
// If this is an *existing* incident
else {
if (streamNotes) {
streamNotes.placeholder = placeholderText;
}
}
}, 2000);
}
Output:
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