What is getControl method in client scripting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 03:45 AM
Hi All,
Can any one explain what actually the getControl method do in client scripting with an example.
Regards
Manohar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 03:55 AM
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';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 04:14 AM
Hi sergiu,
Thanks for quick reply,could you please elaborate the example bcz in my instance it is not working.....
Regards,
Manohar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 04:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 04:28 AM
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)
4. g_form.getControl() not working in Service Portal in Catalog Client Script