Record Producer onLoad Catalog Client Script Function with onChange

CP-UW
Tera Contributor

I have found a couple of posts on here about calling a named function from an onLoad script in an onChange in a form (example below). It is not working for me and I am wondering if it doesn't work with record producers or if I am missing a setting.

 

I get Uncaught ReferenceError: calledFunction is not defined

 

Edit: I have a complex set of hide/show rules given to me by our customer that will require multiple onChange scripts and I'd like to have all of them call a singular function to reduce the amount of code I have to copy into all of them.

 

 

 

function onLoad() {
    // Blank since we're just creating a shared function
    alert("loading");
}

// Shared function that can be accessed by any other client script
function calledFunction() {
    alert("Called");
}
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    
    alert("change running");
    calledFunction();
}

 

 

 

 

1 ACCEPTED SOLUTION

Hello @CP-UW 

I have created a Record producer. Please check the screenshots below of the Onload and Onchange scripts. 

OnLoad Script:

RushiSavarkar_0-1740633339059.png

OnChange Script:

RushiSavarkar_1-1740633392023.png

Result:

RushiSavarkar_2-1740633475636.png

RushiSavarkar_3-1740633525756.png

 

 

Try this code in your instance and let me know.

If it helped, please accept my response as a solution and mark it as helpful

thanks!

View solution in original post

8 REPLIES 8

Rushi Savarkar
Mega Sage

Hello @CP-UW 

Your OnLoad client script should look like this. You have to define the "global" function like below outside the default OnLoad script part

 

function onLoad() {
    // Blank since we're just creating a shared function
    alert("loading");
}
calledFunction = function() { //Call this function from onchange client script
   alert("Called");
};
 
Your OnChange client script looks good. 
If my response helped, please mark it as helpful!
thanks!

If I change the function in the onLoad, I get the error below and the "loading" alert doesn't run

2025-02-26_07-31-21.png

 

If I add var to the beginning, I get the "loading" alert, but then when the function is call from the onChange, I get:

2025-02-26_07-33-08.png

Hello @CP-UW 

I have created a Record producer. Please check the screenshots below of the Onload and Onchange scripts. 

OnLoad Script:

RushiSavarkar_0-1740633339059.png

OnChange Script:

RushiSavarkar_1-1740633392023.png

Result:

RushiSavarkar_2-1740633475636.png

RushiSavarkar_3-1740633525756.png

 

 

Try this code in your instance and let me know.

If it helped, please accept my response as a solution and mark it as helpful

thanks!

I had everything the same. What made the difference for me was setting "Isolate script" (hidden by default in the PDI) to false. Then it worked.