Default Focus Field on Incident Form Load
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2012 01:07 PM
I have a request to set the default focus field on the Incident form to Additional Comments after the initial save. I'm thinking this should be an easy task but I'm not having any luck.
I was able to get it to partially work on an onChange Client script on the Clock No. field but it has some issues when creating a new incident. The code is as follows.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading && newValue == '') {
return;
}
if (newValue != ''){
var field = g_form.getControl('comments');
field.focus();
}
}
When I try to use the onLoad Client Script I can't get it to work at all. I get the alerts to pop up but the focus is still at the caller_id field.
function onLoad() {
var clock = g_form.getValue('caller_id');
alert(clock);
if(clock != ''){
alert('Running if statement.');
var field = g_form.getControl('comments');
field.focus();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2015 01:03 PM
I ended up using:
document.getElementById("IO:<variable sys_id here>").focus();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2015 01:35 PM
I'd suggest you put that line within a try...catch block like so:
try {
document.getElementById("IO:<variable sys_id here>").focus();
} catch(err) {};
That will protect you in case of an error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2015 04:40 AM
Working like a charm, thanks Jim!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2015 06:21 AM
Good to hear, and you are welcome.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2016 08:58 PM
Hello Jim,
How this can be implemented in Service Portal?
I need to focus on a field on change of a variable.
document.getElementById won't work in Service Portal