- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 01:55 AM
I have written an onChange client script that works in my Development instance, but when I try it in my client's environment it doesn't work. I am using getReference to pick a value from a form with a callback, and in the callback function updating values that were first defined early in the overall script. I attached those properties to the window object to make them global and then updated them in the callback functions, then used the values to update my form with setValue. This works fine in my Dev instance.
Now that I have put the same script into my client's test instance, the script doesn't work and I get an error message:
which seems to indicate that the window object doesn't exist. I thought that the window object was always available in javascript?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 02:18 AM
Hi Steve,
Window is null for service portal and this is the basic condition to identify the UI type for service portal.
Supported and unsupported client scripts
But top is accessible in client scripts.
top.location
top.document.getElementById() ......
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 02:06 AM
Hi steave,
window object will support in client scripts, these will support in Desktop UI and not supported in service portal.
Please paste your script here, we try to edit that one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 02:18 AM
Thanks Balaji, here's my script. As you say, it's only in Desktop UI and not used in the service portal.
Here's a plain text version:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || g_form.getValue('impact') == '') {
return;
}
// This takes the first digit of the likelihood and impact fields to calc a score
window.dLik = '0';
window.dImp = '0';
window.Score = 0;
var likRef = g_form.getReference('likelihood',disLik);
var impRef = g_form.getReference('impact',disImp);
}
function disLik(likRef) //reference is passed into callback as first argument
{
window.dLik = likRef.display_value[0]; // extracts the first character from 'likelihood'
}
function disImp(impRef) //reference is passed into callback as first argument
{
window.dImp = impRef.display_value[0]; // extracts the first character from 'impact'
var newScore = calcScore(window.dImp,window.dLik);
g_form.setValue('u_mc_inherent_score',newScore);
}
function calcScore(imp,lik)
{
window.score = imp*lik;
if(score === 0)
{
alert('Likelihood not captured - please try again');
g_form.setValue(control,oldValue) ;
}
return score;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 02:18 AM
Hi Steve,
Window is null for service portal and this is the basic condition to identify the UI type for service portal.
Supported and unsupported client scripts
But top is accessible in client scripts.
top.location
top.document.getElementById() ......
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 02:25 AM
Thanks, Gurpreet.
This is not in the service portal.
Also, I don't understand why it should work in my Dev instance and not in my client's instance.
Steve