OnSubmit Catalog Client script - Form gets submitted before the script is completed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 12:38 AM
Hi All,
I have a requirement where i need to check whether the checkbox variables available on the form are checked or not. Based on that value, i will be doing some calculation at the backend and display the final value in a field on the form. I have a for loop which loops for 69 times(the number of checkbox variables available on the form) and checks whether each checkbox is marked or not. The problem here is, the form gets submitted even before the for loop gets completed. Kindly suggest any method to overcome this issue.
var checked_componenets = [];
var components = g_form.getValue('component_variables');
var component_array = components.split(',');
for(var i=0; i<=(component_array.length); i++){ //array length is 69
if(g_form.getValue(component_array[i]) == 'true'){
checked_componenets.push(component_array[i]);
}
}
if(checked_componenets != ''){
g_form.setValue('all_components',checked_componenets);
}
Thanks in Advance.
Arjun A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 12:55 AM
Hi Arjun,
Have you tried configuring this in a before insert business rule? You can use setAbortAction(true) if your conditions are not met and it runs before the record is submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 01:08 AM
Hi David,
My actual requirement is when user selects certain variables on the catalog item form, based upon the selection it should do a calculation and display the value in a read only field available on the form and also print the message in an alert box. For this i need to check what all variables have been checked by the user on the form and display the value on submission itself.
I am not sure how a business rule will in this scenario. Kindly let me know if any such options possible.
Thanks,
Arjun A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 01:32 AM
Hi Arjun,
I'm not sure how your form works but could you use an onChange script somewhere so run the calculation and display the alert? Perhaps a field the user must change to 'ready' or 'complete' before they can submit the form? onSubmit scripts are used for validation not for modifying the form.
if you need to say, 'if field xyx has not been filled then don't submit the form then you use an onSubmit client script
if you need to say 'if field xyz is this then set field abc to that' then you need to use a before insert business rule
if you need to say 'when field xyz changes set field abc to that' then you use an onChange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 01:40 AM
The problem here is, the form gets submitted even before the for loop gets completed. Kindly suggest any method to overcome this issue.
That's because it's submitted by the client, then your processing works after client submit.
Sounds like you want to move the code to the client so that it kicks off upon an onSubmit event, but before hitting the platform - move it earlier in the processing chain.
However, I'd argue that a form designed with 69 checkboxes indicates you may have more issues than deciding where processing should take place....