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

tobrien
Kilo Guru

Hi, I just recently came across this thread looking to do the same thing -- simply place to focus.



What I discovered was that what you "think" is the element name may not be ...



For example the first line below succeeds, the second does not.



g_form.setValue('asset', '');


g_form.getElement('asset').focus();



When I used Chrome's INSPECT mechanism I saw that the Element ID was a bit more complex...



g_form.setValue('asset', '');


g_form.getElement('sys_display.alm_transfer_order_line.asset').focus();



And now both lines succeed.


Check your console error logs because I got the message that getElement was deprecated.



Re: client script, variable, focus


Sorry, wasn't paying attention to the Portal/Mobile aspect of your original question.




document.getElementById('sys_display.alm_transfer_order_line.asset').focus();


Hi Tony,



I'm trying to set the focus in a catalog item record producer.   When the form loads, the focus is on the list collector variable.   The variable attribute is set to no_filter.   We are on Jakarta, and UI16. I tried A LOT of different coding I found in various threads, but cannot get the focus to the first editable field, or at least the top of the form.



Here is what I tried based on your response to this thread in an onLoad script:



g_form.getElement('sys_display.u_service_request.u_caller_id').focus();



Here is how it loads:


Capture.PNG



Here is what I want:


capture2.png



Any ideas?



Thank you,



Laurie


Hi Laurie,



You (really) should be able to set the focus to anything that has an ID using the DOM stuff I suggested...



The trick for me was using the Browser's INSPECT feature to find the EXACT ID of the element on the served web page, then go back and use it in the



document.getElementById('whatever_you_found').focus();



If this is not working, perhaps you could paste a bit of the web-page source around the thing you want to have the FOCUS.  



The only other thought I have is that it may be the something else is getting the focus AFTER you think you've set it.