client script, variable, focus

scottl
Kilo Sage

In the Service Portal, how does one get a form element variable, of a catalog item, within a client script so one can set the focus on that input?  

22 REPLIES 22

ariesmanlangit
Kilo Expert

Hi,


        I think this is what are you looking for.



  g_form.getElement('<your variable name here>').focus();



        Hope this helps.



a.c.manlangit



serviceNow Developer - Philippines


That method has been deprecated and cannot be used in the Service Portal / Mobile view.


Console: ! (g_form) [DEPRECATED] Method getElement is deprecated and unsupported on mobile


The recommended approach by ServiceNow, 'getReference', doesn't work either as "focus()" is not a valid method on the return object.


g_form.getReference('variable', function(ele){


            ele.focus();


});



Console: ! Error: ele.focus is not a function...



I really cannot understand how difficult this is, just to set the focus on an input field.

Geoffrey2
ServiceNow Employee
ServiceNow Employee

I had a go at this and I can't figure it out either.   The DOM in the Service Portal is completely different to anything we have seen before in ServiceNow. Keep in mind though that the Service Portal is still very new and updates for it are coming out in every Patch. The best thing you can do is log it on Hi so the Service Portal development team know about it.


We're on the latest patch (5) and I also do not have access to HI, while adding a HI ticket doesn't solve the issue at hand either, as I could be waiting months.   Clients do not like to hear that their basic requirements cannot be implemented because SN failed to test their product and allow for basic web functionality.



If anyone figures it out, please update this post.