How do i set the focus on a field after update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2007 03:56 AM
Hello,
Is it possible to set the cursor focus on a specific field after an update of the records in a business script.
after the update i return to the record using :
action.setRedirectURL(current);
Thanks,
Rob Nijbroek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2007 05:21 AM
I don't think this is possible currently. It would be nice to be able to set focus to a specific field on a form after a redirect.
I am not sure if this will help, but you could try using an onLoad client script that would set focus to the field for you if defined conditions are met.
example for incident form:
document.getElementById('incident.short_description').focus();
You would have to clear the condition from the form which was causing the focus to occur if you didn't want the focus to go to the field anymore after the redirect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2007 05:49 AM
It's possible to do this, just a little tricky.
As kcaldwell said, it has to be done via a client script. The integral trick to getting it to work the way you want is to use some fairly obscure GlideSystem/GlideSession manipulation
(Disclaimer: The GlideSession stuff I'm about to describe is all self-taught from SN's javadocs, so it's entirely possible the following code won't work as intended, and it's possible it's not intended to be used this way. Don't try any of this on a live instance, only on a dev instance. As they say, the burned hand teaches best.. and my hand's barely recognizable by this point. 😛 )
Also, all code I'm giving you below is pseudocode; I haven't tested to see if my syntax is exactly correct, etc. It should probably work the way I wrote it, but no guarantees.
Now that the disclaimers are done...
When you run the code that does a redirect, you'll need to grab the user's session. I'll assume this is inside of a button or choice list item.
var myGlideSess = gs.getSession();
Next, you'll store a custom property on their session using "putProperty". The syntax is:
"putProperty(keyName, keyValue)", In the example here, I'll say that you want to focus on "caller_id" on redirect.
var myField = "caller_id";
myGlideSess.putProperty("FieldForFocus", myField);
Next, you'll need a Client-Side script on that particular form; let's say for example's sake that it's on "incident".
function onLoad()
{
funCheckForRefocus();
/* I prefer function calls in onLoad() functions rather than raw */
/* code, because it allows me to simply add new function calls */
/* with less worry about breaking other things. */
}
function funCheckForRefocus()
{
var myGlideSess = gs.getSession();
var myProp = myGlideSess.getProperty("FieldForFocus");
if (myProp == null)
{
/* getProperty returns null if it can't find the property. */
return;
}
else
{
/* Note: Reference fields require 'sys_display.' in front of them to */
/* access the editable field. Non-reference fields don't. So for */
/* comments or short_description, you'd use 'incident.' without */
/* the 'sys_display.'. */
var toFocus = document.getElementById("sys_display.incident." + myProp);
toFocus.focus();
/* Make sure to null the property you set so the user doesn't keep */
/* setting focus to the same field every page load. */
myGlideSess.putProperty("FieldForFocus", null);
}
}
And that should do it for you. If you have the OnLoad script linked to a view, you can make this only function on the specific views you want it to.
Let me know if this was helpful, or if you have any questions. Good luck!
-Drew Lytle
America's Remote Help Desk