Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Shadow text for servicenow forms

tkrishna29
Giga Guru

Hi,

How can I add shadow text for ServiceNow forms? I dont see any option to add it in the Studio - Forms.

I'm looking for something like this (In the text filed - "Optional - Enter Phone No").

find_real_file.png

Any workaround or help is highly appreciated Thank you.

find_real_file.png

1 ACCEPTED SOLUTION

By default, ServiceNow blocks updating DOM objects in scoped applications.


You need to add below system property and set it to false.


glide.script.block.client.globals


screenshot-troweermdev.service-now.com 2017-04-13 23-21-00.png



and use below function to set placeholder text in on load script.


u_addPlaceholderAttribute('field_name', 'YYYY-MM-DD');


function u_addPlaceholderAttribute(variableName, hint) {


  var fieldName;


  try{


  if(variableName.indexOf('phone') >= 0)


  {


  fieldName = g_form.getControl(variableName).name.toString();


  fieldName = 'disp_'+fieldName;


  }


  else{


  fieldName = g_form.getControl(variableName).name.toString();


  }


       


      if (Prototype.Browser.IE) {  


          fieldName.placeholder = hint;  


      } else {  


          $(fieldName).writeAttribute('placeholder', hint);  


      }  


  } catch(err) {}  


}


View solution in original post

16 REPLIES 16

Hi Jim / Nish, still no luck!


$$(fieldName).writeAttribute('placeholder', hint);



find_real_file.png


$j(fieldName).writeAttribute('placeholder', hint);


find_real_file.png


is it a scoped application ?


Yes it is.


find_real_file.png


By default, ServiceNow blocks updating DOM objects in scoped applications.


You need to add below system property and set it to false.


glide.script.block.client.globals


screenshot-troweermdev.service-now.com 2017-04-13 23-21-00.png



and use below function to set placeholder text in on load script.


u_addPlaceholderAttribute('field_name', 'YYYY-MM-DD');


function u_addPlaceholderAttribute(variableName, hint) {


  var fieldName;


  try{


  if(variableName.indexOf('phone') >= 0)


  {


  fieldName = g_form.getControl(variableName).name.toString();


  fieldName = 'disp_'+fieldName;


  }


  else{


  fieldName = g_form.getControl(variableName).name.toString();


  }


       


      if (Prototype.Browser.IE) {  


          fieldName.placeholder = hint;  


      } else {  


          $(fieldName).writeAttribute('placeholder', hint);  


      }  


  } catch(err) {}  


}


Hello Nish,



That was amazing! It worked.


Just curious...how did you find this system property glide.script.block.client.globals ?


I checked in the system properties from link below and I didn't see this -


http://wiki.servicenow.com/index.php?title=Available_System_Properties#gsc.tab=0



Thank you Jim & Nish for your support. It was of   great help!