Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Client Script onChange is not triggering at all

colin-lucwe
Tera Contributor

Hi everyone,

I’m currently facing an issue with a Client Script onChange script that is not being executed at all.

The strange thing is that it is not a logic issue inside the script — the script does not seem to trigger in the first place. I already added logging statements at the very beginning of the Client Script, but nothing appears in the console/logs when I change the field value.

Has anyone experienced a similar issue or has an idea what could prevent an onChange Client Script from firing?

Things I already checked:

The Client Script is active
The field name is correct
The script type is set to onChange
I tested with simple log statements at the first line
The field value is definitely changing
Are there any less obvious reasons why an onChange Client Script would not trigger at all? For example, any configuration settings, UI policies, field types, client conditions, or other dependencies that could block it?

Any hints or troubleshooting tips would be highly appreciated. Thanks!

19 REPLIES 19

colinlucwe_0-1785395815336.png

the value changes if i change the Account 

yes so instead of setting empty - as seen in your script it is setting some different value from other script or configuration..

also check g_form.clearValue('contact');

instead of setValue!

the script itself is not the Problem, the Script doesnt even start

are you checking the browser console (as you have console.log),

if yes then It means the function is never being invoked by the platform, which points to something like UI Builder/Workspace not classic Client Scripts, a table mismatch, or a scoped duplicate..

 

if no then try this script :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    g_form.addInfoMessage("onChange fired | isLoading: " + isLoading + " | newValue: " + newValue + " | oldValue: " + oldValue);

    if (isLoading || newValue === '') {
        g_form.addInfoMessage("Returning early - isLoading or empty newValue");
        return;
    }
    g_form.addInfoMessage("Passed guard clause, proceeding with clear logic");

    //location is already cleared and reset in CASE - Fill on Account change
    //g_form.setValue("location", "");
    g_form.setValue("contact", "");
    g_form.setValue("entitlement", "");
    //if global variable == false don't clear ci (triggered by script on CI Change)
}

 

If my response helped mark as helpful and accept the solution.

 

stevenatwork
Tera Expert

Hi,

I suspect the below.

  1. Programmatic updates with suppressed events
    If the Account field is being set by another script or UI Policy using g_form.setValue('account', value, displayValue, false), passing false explicitly suppresses onChange events from firing.
  2. JavaScript errors breaking the browser queue
    If another Client Script, UI Policy, or DOM manipulate script throws an unhandled JS error when the user interacts with the page, it halts the browser's script execution chain before this script can run.