Work notes field not displaying placeholder text in the existing incidents

kandulek
Tera Contributor

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!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@kandulek 

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:

placeholder text for work notes new and existing record.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Rafael Batistot
Tera Sage

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).

 

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.

 

kandulek_0-1757519553566.png

Ankur Bawiskar
Tera Patron
Tera Patron

@kandulek 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@kandulek 

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:

placeholder text for work notes new and existing record.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader