- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 07:39 AM - edited 02-26-2025 07:57 AM
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();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 09:19 PM
Hello @CP-UW
I have created a Record producer. Please check the screenshots below of the Onload and Onchange scripts.
OnLoad Script:
OnChange Script:
Result:
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!
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 09:40 PM - edited 02-25-2025 09:41 PM
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
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 07:36 AM
If I change the function in the onLoad, I get the error below and the "loading" alert doesn't run
If I add var to the beginning, I get the "loading" alert, but then when the function is call from the onChange, I get:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 09:19 PM
Hello @CP-UW
I have created a Record producer. Please check the screenshots below of the Onload and Onchange scripts.
OnLoad Script:
OnChange Script:
Result:
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!
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 01:07 PM
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.