- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2015 01:59 PM
The system I work on displays a closure section when incidents are marked as closed, which is done with a drop-down menu vs. a UI action. The section is off the screen, however, and it is confusing because users don't know it is there until they hit update and get an error popup. I am trying to change the focus with a UI Policy or onChange Client Script, but nothing has worked so far.
In my Client Script, I know I have the field change detecting correctly because I have an alert popping up. I have tried using the g_tabs2Sections API:
1) by putting in the section numbers directly (.setActive(2))
2) by looking up the section ID in the source and finding the index of that sysID (.findTabIndexByID(sysID)), which was returning 1.
Neither section number is setting the focus. What am I doing wrong?
Here is the main part of the script:
var id = g_tabs2Sections.findTabIndexByID('section_tab.12345678...');
alert('id = ' + id);
g_tabs2Sections.setActive(id);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015 12:32 PM
Hi Justin,
I don't know what's causing the issue, but you could try wrapping that part in a timeout:
setTimeout(function() {g_form.getElement('incident.close_notes').focus();},0);
That way it executes after the client script finishes- perhaps the element has to hold focus for the duration of the script execution. That sounds plausible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015 01:01 PM
Cory,
You are the man! I had tried the setTimeout function but used slightly different syntax, which was unsuccessful. This worked perfectly.
Thanks!
Justin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015 01:28 PM
I agree with Cory.
Justin,
What do you get if you simple alert g_form.getElement('incident.close_notes')? Also is this script working on load or change of the page. Since the tab is hidden the field could be hidden so the it might require to first make the tab visible before setting focus on the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015 01:42 PM
Venkat,
Yes, that is what I ended up with. It is an onChange client script that sets the active tab and then refocuses to a field on that tab. Everything is working great now.
Thanks,
Justin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 08:47 AM
Would you mind sharing your finished script Justin as I have a very similar requirement
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2017 06:55 AM
Angus - Sure, but I have to re-type since our system is not connected to the internet. If you try it and run into a problem, let me know as I may have entered a typo. Also, if you need help with the section sys_id, go to System UI -> Form Sections and search for the form section on the table you need.
Thanks,
Justin
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Change to Closure tab when incident state is closed
if (newValue == 7 || newValue == 8 || newValue == 12) {
var id = g_tabs2Sections.findTabIndexByID('section_tab.[your section sys_id here]'); //"Closure Information"
g_tabs2Sections.setActive(id);
setTimeout(function() {g_form.getElement('incident.close_notes').focus();},0);
document.getElementId("label.incident.close_notes").hint = "Description of the actions taken to investigate and resolve this incident.";
}
}