The window object not available in a client script

lawrenson
Giga Contributor

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:

find_real_file.png

which seems to indicate that the window object doesn't exist.   I thought that the window object was always available in javascript?

1 ACCEPTED SOLUTION

Gurpreet07
Mega Sage

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() ......


View solution in original post

6 REPLIES 6

BALAJI40
Mega Sage

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.


Thanks Balaji, here's my script. As you say, it's only in Desktop UI and not used in the service portal.


find_real_file.png


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;


}


Gurpreet07
Mega Sage

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() ......


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