- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 11:31 AM
Hello,
I have a Service Catalog Record Producer, with a list collector in the middle of the form. When the form loads, I want the focus to be at the top of the form, or at least set to the first editable field. In an onLoad Client Script I tried the following, individually, to no avail:
setTimeout ( "var refocus = g_form.getElement('table_name.field_name');refocus.focus();" , 0 ) ; }
------------------------------------------------------------------------------------------------------------------------------------
(function($) {
var fieldname = 'start_date';
$(g_form.getControl(fieldname)).focus();
})(jQuery.noConflict());
------------------------------------------------------------------------------------------------------------------------------------
And various other getElementById()
Here is how the form loads:
This is how I want it to load:
Thank you in advance,
Laurie
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 06:20 AM
Hi Anjaneyulu,
Actually, I discovered it was something else causing the focus not to be at the top of the page. We have a client script that displays a field message at the bottom of a field (which is in the middle of the form). I had to add the "false" parameter to the function. Without "false", the focus is set to that field with the message when the form loads.
function onLoad() {
g_form.showFieldMsg('u_ncpi_information','Sensitive NCPI Information should only be entered in the above box.','error',false);
}
Thanks,
Laurie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2017 06:01 AM
Hi Laurie,
Can you share complete script for onLoad. That should work.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2017 06:22 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2017 06:32 AM
have you created custom caller field u_caller_id? if not then it should be caller_id.
function onLoad ( ) {
setTimeout ( "var refocus = g_form.getElement('u_service_request.caller_id');refocus.focus();" , 0 ) ; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2017 07:03 AM
Yes, we have a custom u_caller_id field on our Service Requests.