reload form on client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 12:33 PM
Hi,
I wrote onchange client script which checks if the value in a filed is valid or not. If it is invalid i need to reload the form so that it get the previous value on that field.
How should i do that in client script. Please let me know.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 12:55 PM
Hi Chuck,
function isOrderSubmitted () {
if(g_form.getValue('status') == 'order_submitted' || g_form.getValue('status') == 'order_approved' || g_form.getValue('status') == 'accepted' || g_form.getValue('status') == 'rejected' || g_form.getValue('status') == 'cancelled')
{
g_form.addErrorMessage('Sales Type Value cannot be altered once Order is submitted. ');
g_form.setValue('partnership_type',oldValue);
return true;
}
}
When i set the value here it is triggering into infinite loop. Just tested it.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 01:01 PM
Don't return true, just return, or return false.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 01:03 PM
FYI - returning true is typical programmer speak for "everything worked, I'm good - go on and do what you need to do." Returning false, on the other hand, is a convention for saying "something went wrong."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 01:13 PM
I have to admit, I didn't see the function "isOrderSubmitted()" and hope that this is enclosed within the standard onChange template function. If not, your function should look like this to provide you with the newValue and oldValue stuff...
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(g_form.getValue('status') == 'order_submitted' || g_form.getValue('status') == 'order_approved' || g_form.getValue('status') == 'accepted' || g_form.getValue('status') == 'rejected' || g_form.getValue('status') == 'cancelled')
{
g_form.addErrorMessage('Sales Type Value cannot be altered once Order is submitted. ');
g_form.setValue('partnership_type',oldValue);
return;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 12:49 PM
How are you setting the old value, if you are using g_form.setValue it would trigger the loop. Try either control.value = oldValue or alternatively just return
- if (isLoading || newValue === '' || newValue is Invalid) {
- return;
- }