Condition/OnClick field on a client script for a record producer

Jason Stephens
Kilo Guru

I am trying to run a client script ONLY if a field on my form (caller_id) is not empty. Otherwise, I do not want it to run. I would assume I could put caller_id!='' in the condition/OnClick field to accomplish this, but it doesn't work. Why doesn't this work?

14 REPLIES 14

The last comment was out of sync with you guys.... OK this gets me closer. It is just displaying the name of the person twice instead of the name and employee id so this should get me where i need to be.

Thank you both very much for the help.


Also consider doing a calculated field if it doesn't need to run in the user interface. So for your u_caller_user_id you could go it's dictionary entry and click "calculated" and use the calculation:

current.caller_id.getDisplayValue()


Your parentheses were in the wrong place in the getValue part of your "if" statement so you were likely getting a JavaScript error which stops your code from running. You could do something like the code below to do it quickly. The g_form.getReference function makes a call back to the server and returns an entire record not sure the user's name so it's very expensive in terms of time to execute. It would be nice if we had a g_form.getDisplayValue function to use but this should work until then.

function onLoad() {
if (g_form.getValue('caller_id') != '') {
var callerID = gel('sys_display.incident.caller_id');
if (callerID)
g_form.setValue('u_caller_user_id', callerID.value);
}
}


Ugh. If it's not a semicolon it's a misplaced parentheses. I missed that one :).


Here's the whole story - maybe you can suggest a better way..

I have an Incident record producer that has variables for name, contact#, and description of issue. I want to populate the employee id # on the incident form based on the name entered. Right now, I built with the assumption that the logged in user would be the "name". If I do that, I just grab the associated ID # and populate the field - no big deal. BUT - if the logged in person changes the name to someone else (say like an "on behalf of"), then I need to be able to change the associated ID on the fly...

I can get this to work with the script I attached, but when the Help Desk goes to create a new incident, they see "undefined" in the employee id field - because the onload script is looking for a name to use in order to fill in the ID #. That's what lead me to trying to build a condition. I only need it to run when it has a name to use....