Set Focus to a specific Catalog Item variable in the Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 11:36 AM
Greetings,
Does anyone have a way of setting the current focus to a specific variable on a catalog item? I'm trying to do this in an onChange Client Script. The following two options both work in the Native UI however, neither work in the portal and the following error is presented: "There is a JavaScript error in your browser console".
Option 1
var refocus = g_form.getElement('[variable_name]');
refocus.focus();
Option 2
g_form.getControl('[variable_name]').focus();
Thanks, in advance for your time.
E
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 11:45 AM
You need to have the code something like this:
function onLoad() {
setTimeout("var refocus = document.getElementById('IO:<<sys_id of the entry of that variable>>');refocus.focus();",0);
}
REgards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 09:34 AM
Thank you for this suggestion however, while it works in the Native UI, it produces a JavaScript error in the Portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 11:45 AM
In Service Portal getElement and getControl do not work. You can get this to work, obviously a little "hacky":
a) Make sure your "UI Type" is "All":
b) You can use the following line of code:
setTimeout("var refocus = document.getElementById('sp_formfield_u_account_name');refocus.focus();",0);
(Obviously replacing u_account_name with the name of your variable)
The big downside is that this can break on upgrade. For example it previously required the sys_id not the variable name.
I'm more than happy to be corrected and told there is a way it works in Service Portal using out of box. I just know of nothing.