client script, variable, focus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2016 02:52 PM
In the Service Portal, how does one get a form element variable, of a catalog item, within a client script so one can set the focus on that input?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2016 07:42 PM
Hi,
I think this is what are you looking for.
g_form.getElement('<your variable name here>').focus();
Hope this helps.
a.c.manlangit
serviceNow Developer - Philippines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2016 08:55 PM
That method has been deprecated and cannot be used in the Service Portal / Mobile view.
Console: ! (g_form) [DEPRECATED] Method getElement is deprecated and unsupported on mobile
The recommended approach by ServiceNow, 'getReference', doesn't work either as "focus()" is not a valid method on the return object.
g_form.getReference('variable', function(ele){
ele.focus();
});
Console: ! Error: ele.focus is not a function...
I really cannot understand how difficult this is, just to set the focus on an input field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2016 10:32 PM
I had a go at this and I can't figure it out either. The DOM in the Service Portal is completely different to anything we have seen before in ServiceNow. Keep in mind though that the Service Portal is still very new and updates for it are coming out in every Patch. The best thing you can do is log it on Hi so the Service Portal development team know about it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2016 12:23 AM
We're on the latest patch (5) and I also do not have access to HI, while adding a HI ticket doesn't solve the issue at hand either, as I could be waiting months. Clients do not like to hear that their basic requirements cannot be implemented because SN failed to test their product and allow for basic web functionality.
If anyone figures it out, please update this post.