client script, variable, focus

scottl
Kilo Sage

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?  

22 REPLIES 22

Wait, I think I didn't explain very well.   The record producer catalog form works fine, repeatedly.   When I go the the actual form that is created FROM the record producer (for example incident), then THAT form focuses on the watch list.   Incidents, NOT created from the record producer do NOT behave this way.



Is your response still the same?



Thanks,



Laurie


So just to ensure my understanding... please reply with anything I am going sideways on.



1. The CATALOG ITEM side of things is fine.


2. You can create INCIDENTs in a variety of ways, and *sometimes* they are being created by your "record producer" catalog item.


3. If you open an INCIDENT created by any means *other than* your record producer, they open with the focus where you want.


4. Opening an INCIDENT created by your record producer starts with the focus elsewhere (i.e. the watch list)



Correct?


Correct!


Great!


{so talking out loud to myself }



The Record Producer is simply adding a new row into the Incident's Table. It has NO control over what UI aspects occur when you "open" it... e.g. there could be UI Policies, OnLoad() client side scripts, ACLs, and the like... all kinds of magic can happen "after the fact"



So really there is no reason why she can't locate an element and set the focus in the OnLoad...



{stops talking to himself}



How about this --> open one of each of the 2 kinds of Incidents. Using the INSPECT (or Page Source) of the browser, find some "common" element between the 2 like, say, the INCIDENT NUMBER at the top ...   in my instance it has an id as so ==>



id="sys_original.incident.number"



Then add your FOCUS statement to any of the OnLoad() clients scripts for Incident.



document.getElementById('sys_original.incident.number').focus()




And lets make sure that works for BOTH


Well, as it turns out, there is an onLoad client script that has the following code:



g_form.showFieldMsg('u_ncpi_information','Sensitive NCPI Information should only be entered in the above box.','error');



This is what is causing the issue.   The showFieldMsg is setting the focus, and it just so happens the Watch List is above that field.   So its not my record producer!   I think I will need to add the focus into that client script to fix the issue.



Thank you so much for your help!