Shiva Thomas
Kilo Sage

Header.png

As a software platform, ServiceNow has a great and modern GUI that works with any web browser. Yet there is one glaring missing UI feature from modern web technology: HTML Placeholders. Let me present you this ninj'admin trick that you can use on your implementations.

What are HTML Placeholders?

Placeholders are the ghost texts present in many web sites' input fields. They are an old trick introduced with the HTML5 norm, back in 2011.

The most common usage is with Search input fields.

Placeholders - Search.png

As soon as you type something in the box, the placeholder text will disappear, to be replaced by your own input.

Used in the Service Catalog, or in your Forms, they can add useful information without being obnoxious for the users.

Placeholders - SC with.png

ServiceNow current help system for the Service Catalog is way more obnoxious to my liking. Placeholders are way better design-wise.

Placeholders - SC without.png

Native support in Jakarta Service Catalog

In Jakarta, HTML Placeholders can only be configured for for Service Catalog variables via the field "Example Text" that you'll have to add to the Variable Form.

You can only apply them for: Single Line Text, Wide Single Line Text, Multi Line Text, IP Address, Email, URL, Date, Date/Time.

In Jakarta, there is no native function to add HTML Placeholder to your forms outside Service Catalog Variable.

Not using Jakarta? Want them outside the Service Catalog? Script your placeholders

If you are using an older version, you can use this simple client script to add placeholders to your forms.

Platform interface

I recommend adding the feature globally using a UI Script include.

Placeholders - UI Script.png

You'll now be able to add lean onLoad Client Script to the forms of relevant tables.

Placeholders - OnLoad Client Script.png

Another great thread on the subject: Support for HTML 5 placeholder attribute

Catalog Items & Record Producers

The same design works, with some minor adaptations. The scripts should be added to the 'Catalog Client Script' table instead. Also, catalog items and record producers will not load the UI Scripts, so you'll have to copy the whole addHtlmPlaceholder function directly in each 'Catalog Client Script'.

Placeholders - Catalog Client Script.png

Styling Placeholders

Placeholders appearance can be easily modified via CSS, using the: :placeholder pseudo element.

Limitations

  • Placeholder texts must not contain carriage returns or line-feeds.
  • They won't be applied to reference fields, nor on journaled fields grouped under UI16's Activity.
  • They will not work with the Service Portal or mobile interfaces. The Mobile GlideForm (g_form) is currently too limited, and DOM Manipulation using stuff like $ and jQueryare prohibited by the platform.
  • In scoped applications, ServiceNow blocks updating DOM objects. You'll need to add System Property "glide.script.block.client.globals" and set it to false.

Script examples… Ready to use

UI Script

var uiShiva = {

addHtlmPlaceholder: function (fieldName, placeholderText) {

  try {

    if (g_form.hasField(fieldName)) {

      var control = g_form.getControl(fieldName).name.toString(); // getControl is currently not supported in Mobile g_form

      if (Prototype.Browser.IE) // Internet Explorer only

        fieldName.placeholder = placeholderText;

      else // Other browsers, using jQuery (not supported in Service Portals or mobile UI)

        $(control).writeAttribute('placeholder', placeholderText);

    }

  }

  catch(err) {} // Fail silently

}

};

Client Script onLoad, Desktop

function onLoad() {

uiShiva.addHtlmPlaceholder('close_notes', 'The close note is only visible to fulfillers and should contains technical info over the resolution.');

uiShiva.addHtlmPlaceholder('another_field', 'Another example');

}

Catalog Client Script onLoad, Desktop

Merged as a single script

function onLoad() {

addHtlmPlaceholder('short_description', 'Mandatory short title');

addHtlmPlaceholder('business_case', 'Take a few moments to briefly explain your idea. Upon receipt, your Demand Manager will review the request and contact you for next steps.');

function addHtlmPlaceholder (fieldName, placeholderText) {

  // Add HTML Placeholder to forms. Won't work for Mobile / Service Portal scripts.

  // This is a workaround until Jakarta, as it should bring native support for placeholder attribute.

  try {

    if (g_form.hasField(fieldName)) {

      var control = g_form.getControl(fieldName).name.toString();

      if (Prototype.Browser.IE) // Workaround for Internet Explorer

        fieldName.placeholder = placeholderText;

      else // Modern browsers, using jQuery (Not supported in Service Portals or mobile UI)

        $(control).writeAttribute('placeholder', placeholderText);

    }

  }

  catch(err) {} // Fail silently

}

}

Originally published in servicenow.implementation.blog by Shiva Thomas

20 Comments
sdepally
Kilo Contributor

Hi Shiva,

 

Can we have this working on form field which is of type "HTML"?

 

Best

Srikanth

Matang Surti
Tera Contributor

Hi @Shiva Thomas ,

This is not working for "Additional Comments" and "Woke notes" field's placeholder. Can you help me how to change the placeholder values for this two fields?

Thanks,

Matang

Shiva Thomas
Kilo Sage

Hi @Matang Surti ,

The widget used to display journaled fields, like "Additional Comments" and "Woke notes" is a non-standard one. I did not found the time to see if there was a way to overide this.

∴
Best regards from Switzerland
Shiva :¬,

If this reply assisted you, please consider marking it 👍Helpful.
This enables other customers to learn from this thread.

Cheryl H_
Giga Contributor

Where can we find updates for this for any new releases?

Priscila Lisson
Giga Contributor

Very good.

SusanWinKY
Mega Sage

Has this stopped working for anyone recently? We've seen it stop within the last day or so. Wondering if a browser update has caused it.

Mike McCall
Giga Guru

Hmm, what setup do you have: "Example Text" on a variable, or the custom approach?

Also, when you say it stopped working, do you mean that fields now appear blank instead of having placeholder text...or is something worse happening on your form?

(Using the current version of Microsoft Edge, I just pulled up a catalog item in our service portal, and I didn't see any issues with our setup.)

SusanWinKY
Mega Sage

We were using this to set placeholder text for the Description field on a Decision record. We had a UI Policy with this...

function onCondition() {
 var field1 = g_form.getControl('description');
 PlaceHolderAttributes.addHtlmPlaceholder('description',"some placeholder text here"); // PlaceHolderAttributes is our UI Script
}

and fixed the issue by updating it to...

function onCondition() {
    var field1 = g_form.getControl('description');
    field1.placeholder = "some placeholder text here";
}

The PlaceHolderAttributes UI Script is exactly as Shiva's except for the name.

This fix is working for Chrome, Edge, and Firefox - the ony browsers I have installed. 🙂

 

SusanWinKY
Mega Sage

Also... we have another UI Script that is throwing an error when the page loads. Deactivating that fixes the issue but we can't keep it deactivated. So the above fix was our chosen solution.

Mike McCall
Giga Guru

Wow, that makes it look like the UI script labeled as "Internet Explorer only" now works across all the real browsers.

Maybe it's revenge for all the bad things we say about IE!