- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 11:56 AM
On a record producer, I have three fields I have to look at the values for in order to determine some other show/hide rules for the form.
I have successfully scripted three client scripts (one for each field) to determine if some other variables will show and become mandatory (i'll call these dependent fields). But because these client scripts don't talk to eachother, it is not a good solution since changing a value on one of the three fields may hide the dependent fields, when they should be showing according to one of the other client scripts.
I wanted to just get it working before I worked towards using this solution (the accepted solution) to consolidate all three scripts into functions on an onLoad client script.
It doesn't look like this is working for me however, and I'm not sure if it's because they are catalog client scripts or for another reason.
Right now, my onLoad client script looks like this:
function onLoad() {
//Type appropriate comment here, and begin script below
}
function checkPrimaryRole() {
alert('in the function');
}
and the onChange script that I am trying to call the checkPrimaryRole function from looks like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
checkPrimaryRole();
}
I just put an alert in the function just to try to see if i can get that working before adding all my code, but can not get the alert to come up.
Is there something I'm doing wrong in my client scripts for this solution?
Is there a better way that anyone recommends to achieve what I need (essentially an onChange client script on three different variables, but they all would do the same thing)
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 02:39 PM
You need to disable "Isolate script" on your onLoad script (all new client scripts have this field enabled by default). The Isolate script setting probably won't be on your form view unless someone already added it, so you can either update your form view to include it or edit the setting from the list view.
I believe Isolate script has to be disabled because the functions and variables that you declare outside of the onLoad() function are actually being attached to the window object, but the script can't attach things to the window object when Isolate script is true. Since that is the case, you might want to be careful about how you name your custom variables and functions so that you don't accidentally overload an existing property of the window object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 02:39 PM
You need to disable "Isolate script" on your onLoad script (all new client scripts have this field enabled by default). The Isolate script setting probably won't be on your form view unless someone already added it, so you can either update your form view to include it or edit the setting from the list view.
I believe Isolate script has to be disabled because the functions and variables that you declare outside of the onLoad() function are actually being attached to the window object, but the script can't attach things to the window object when Isolate script is true. Since that is the case, you might want to be careful about how you name your custom variables and functions so that you don't accidentally overload an existing property of the window object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 01:16 PM
Disabling "Isolate script" is enough to make this work in the platform (UI16) and Service Catalog (CMS) view, but I just realized you need to do one more thing if you want this to work in Service Portal. You need to change the way you are declaring your function, and make sure you do not use the var keyword.
function onLoad() {
//Type appropriate comment here, and begin script below
}
checkPrimaryRole = function() {
alert('in the function');
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2021 01:44 AM
Thank you! This solved my issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2020 11:38 AM
that's it. thank you!