prevent onChange client script working on onLoad

onferns
Kilo Expert

I have the following code added to my onChange client script but it still runs on form load:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

      // Consider the Empty Duration

      if ( isLoading || g_scratchpad.flag || !g_scratchpad.projectTaskSysId) {

              g_scratchpad.flag = false;

              return;

      }

the scratch pad variable projectTaskSysId is set by a Display BR it will contain the task's sys id.

Can some one help me point out how i can disable ithe Client script's execution on form load.

2 REPLIES 2

Brian O_Donnell
Tera Guru

What indicator do you have that it is executing? (other than g_scratchpad.flag being set since that will always happen onLoad)



if you want to make sure that it never runs onLoad then change it to:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {  


      if (isLoading)


return;



  // Consider the Empty Duration  


      if ( g_scratchpad.flag || !g_scratchpad.projectTaskSysId) {  


              g_scratchpad.flag = false;  


              return;  


      }  


harmangill02
Mega Expert

function onChange(control, oldValue, newValue, isLoading, isTemplate) {


//Consider the Empty Duration


if ( isLoading || g_scratchpad.flag || !g_scratchpad.projectTaskSysId) {  


g_scratchpad.flag = false;


return;


}




The reason why it is executing is that your IF statement returns true because of the "isLoading" condition. Brian's suggestion should work, if you would not like it to execute when the record loads.



Thanks!