How to set focus on a Record Producer form?

Laurie Marlowe1
Kilo Sage

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:

Capture.PNG

This is how I want it to load:

capture2.png

Thank you in advance,

Laurie

1 ACCEPTED SOLUTION

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


View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

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


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,



Here is the onLoad script:



function onLoad() {


setTimeout("var refocus = g_form.getElement('u_service_request.u_caller_id');refocus.focus();" , 0 ) ;


}



Capture.PNG



The list collector has a variable attribute set:   no_filter



Thank you,



Laurie


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 ) ; }


Yes, we have a custom u_caller_id field on our Service Requests.