client script, variable, focus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2016 02:52 PM
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?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 07:48 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 02:23 PM
Check your console error logs because I got the message that getElement was deprecated.
Re: client script, variable, focus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 04:31 AM
Sorry, wasn't paying attention to the Portal/Mobile aspect of your original question.
document.getElementById('sys_display.alm_transfer_order_line.asset').focus();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2017 08:56 AM
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:
Here is what I want:
Any ideas?
Thank you,
Laurie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2017 09:48 AM
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.