Set Focus to a specific Catalog Item variable in the Portal

M_ Elliott Holc
Giga Contributor

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

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

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

Thank you for this suggestion however, while it works in the Native UI, it produces a JavaScript error in the Portal.

TrevorK
Kilo Sage

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":
find_real_file.png

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.