What is getControl method in client scripting?

bmanoharreddy7
Kilo Contributor

Hi All,

Can any one explain what actually the getControl method do in client scripting with an example.

Regards

Manohar

5 REPLIES 5

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Here:



GlideForm (g form) - ServiceNow Wiki



10.2 getControl

HTMLElement getControl(fieldName)


Returns the HTML element for the specified field. Compound fields may contain several HTML elements.
Generally not necessary as there are built-in methods that use the fields on the form.
Parameters:
fieldName - specifies the name of the field.
Returns:
HTMLElement - the specified HTML element(s).
Note: If the field is of type reference and the control is a choice list, getControl() may not return control as expected. In this case, use sys_select.<table name>.<field name>.
function onLoad() {

g_form.getControl('sys_display.rm_defect.assignment_group').style.width = '350px';


}


Hi sergiu,



Thanks for quick reply,could you please elaborate the example bcz in my instance it is not working.....



Regards,


Manohar


What exactly are you trying to achieve in the first place?



If you go to Client Scripts in the instance and search for Script contains getControl you'll find many examples:



https://<instancename>.service-now.com/sys_script_client_list.do?sysparm_query=sys_class_name%3Dsys_script_client%5EscriptLIKEgetControl


Hi Manohar,



This could be due to following issues :



1. If the field is of type reference and the control is a choice list, getControl() may not return control as expected. In this case, use sys_select.<table name>.<field name>.


2. ServiceNow KB:   The g_form.getControl method does not work after ordering   (KB0547171)


3. getControl not working


4. g_form.getControl() not working in Service Portal in Catalog Client Script