How to store and reuse the value in catalog client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 01:57 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 03:33 AM
You need to declare the variable outside the onChange function. If still its not working then you could create a another function in onChange script to return value and then call that function in onsubmit script .
OnChange Script:
var test = '' ;
function onChange(){
test = "testValue" ;
}
function getValueOfTest(){
return test ;
}
OnSubmit Script:
function onSubmit(){
var test2 = getValueOfTest();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 08:15 PM
This works:
OnChange Script:
test="test1";
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
test ="test2";
//Type appropriate comment here, and begin script below
}
OnSubmit Script:
function onSubmit() {
//Type appropriate comment here, and begin script below
alert(test);
return false;
}
Regards,
Mujtaba Bhat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2015 05:59 AM
Yes this one is working.
Actually the problem was with the keyword "var". If we declare the variable with var then it would not be global.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 11:30 PM
Hi Rajeev, you can do the following steps:
a) You can create a variable in your Catalog Item as a catalog item variable
b) Through a UI catalog policy you can manage the visible of this catalog variable. I guess you will like to make not visible.
c) You can simply set that variable on your client onchange catalog script and then use that variable in your onSubmit catalog script.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2015 10:42 PM
Thanks Berny.
Indeed we adopted this approach only.