Clearing fields after clicking "Add to cart " in service portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2018 07:00 PM
Hi,
We are migrating from from CMS to Service portal.
We are facing an issue related to " add to cart".
The user needs the capability to refill data in form after adding entered details to cart.
I believe this can achieved by by clearing/ resetting the widget fields, but not sure how to get this done.
anyone faced the same issue/ implemented a similar functionality ?
Thanks,
Satheesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2018 09:41 PM
Simple way around this would be to redirect the user on the client-side with an onSubmit client script. You could redirect the user to the current catalog item - grab its unid dynamically - using window.location = x; This will add the item to the user's cart and reload the current form.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2018 09:42 PM
I just tested a solution that I think will work for you. You'll have to take ownership of the 'SC Catalog Item' widget but you can clone it and then add the following right at the bottom of the 'addToCart' function in the 'Client Script' section of the widget. It iterates through all of the catalog item variables every time the 'Add to Cart' button is clicked and clears out the values.
// Clear all field values after submit to refresh the form
var allFields = g_form.getFieldNames();
for (var fieldName in allFields) {
g_form.clearValue(allFields[fieldName]);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2018 10:58 PM
Hi Mark,
the above script will clear everything but we need only user enetered data to be cleared.
do we have a way to reload the current page! from client scripts?
thanks,
satheesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 05:17 AM
You can just reload the page, but it's really clunky and destroys the 'Add to Cart' UI message that comes up because it's reloading the entire page, not just the catalog item. If you wanted to do that, you could add the following line in place of the code I gave you before right at the end of the 'addToCart' button.
reloadWindow(window);