How to store and reuse the value in catalog client scripts

rajeev_kumar
Mega Contributor

We have a catalog item. In this catalog item we have a input field "Field1".

Now onChange of this field we check if this value is already exist on the server by using GlideAjax.   We want to to same thing onSubmit as well, but we do not want to make server call.

One way of doing it is save the result in a variable on onChange event (by GlideAjax) and get the value of this variable on onSubmit and take appropriate action.

Second way is to make GlideAjax call again on onSubmit.

Is there any other way to achieve this without variable/GlideAjax ?

Thanks,

Rajeev.

9 REPLIES 9

Mujtaba Amin Bh
Mega Guru

Rajeev,



You can get the saved value from server onload of the form in some variable and then compare.



But I am unable to understand the reason why are you doing it.


Gurpreet07
Mega Sage

Declare the variable globally in onchange client script and then use the same variable in onSubmit script



var test = '' ;


function onChange(){


test   =   "testValue" ;


}




OnSubmit Script:


function onSubmit(){


var test2 = test ;


}


tkalpa005
Tera Expert

Hi,


This my help you


Create a variable in On-change script Globally, then use it in on-submit script



var varGlobal= '' ;


function onChange(){


varGlobal=   "your value" ;


}


In On submit script use that varibale


function onSubmit(){


var variableLocal = varGlobal;


}


Thanks


KB    


I tried your suggestion but in the onSubmit() this variable is not available. I tried to alert the value of this global variable which is declared in onChange script.


When I used try catch block . it shows the below error.


"ReferenceError: varGlobal is not defined"


Is it mentioned somewhere on wiki ? I tried to search global variables in catalogClient Script but I did not find anything.



Thanks,


Rajeev