What does the method getControl do exactly. Please someone explain with an example getControl

prem_vikas_k
Giga Contributor

Example

    if (!g_form.getControl('location'))

          return;

3 REPLIES 3

Geoffrey2
ServiceNow Employee
ServiceNow Employee

It's similar to document.getElementById('id').   It gets the element with the field name you specify (not an id).


It's important for fields like Reference fields which are actually made up of several different input fields in the DOM (one for the sys_id, one for the display value, etc).


getControl() knows which input element to get.


BALAJI40
Mega Sage

As sage said, it will execute like that.


One more information on getControl() was it was depreciated method for mobile.,It returns the the html field of element.


hasFiled() also same functionality of getControl().


hasFiled() - executes in both mobile and desktop. But getControl() - executes in desktop only.


for ex: (BP) Set Location to User refer this on incident form.


Hi Balaji,



I have this code to display ghost text in the record producer, this is working for ESS view as we have getControl method the functionality is not working in Service Portal (as this method have been deprecated for the mobile platform and service portal).


I tried using g_form.hasField which did not work.



function onLoad() {


var name = g_form.getControl('u_application_name');


  if(name !== null)


    name.placeholder = "Common name for the application";


    }



Can you help me in achieving this functionality.



Regards,


Bargavi.