Cart Duplicate Validation in ServiceNow Based on Requested For and Application Name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 03:07 AM - edited 11-27-2024 01:53 AM
I have implemented a functionality in a ServiceNow catalog item where, when the user clicks the "Add to Cart" button, the system checks if an item with the same combination of requested_for and application_name already exists in the cart. If a duplicate is found, an error message appears: "You cannot add the same request to the cart without any changes." The functionality works as expected, ensuring duplicates are not added to the cart. However, if either requested_for is different while the application_name remains the same, or if application_name is different while the requested_for remains the same, or both fields differ, the item should be allowed to be added to the cart.
Additionally, the client requires a hidden key field to store the concatenation of requested_for and application_name. This key value is passed to the onSubmit client script to validate duplicates. The system should also be capable of handling unique combinations of requested_for, application_name, and possibly environment in the future.
Currently, this validation is working perfectly but triggers for both "Add to Cart" and "Order Now" buttons. I need help modifying the functionality so that it only triggers when the user clicks the "Add to Cart" button. The "Order Now" button should bypass the duplicate check and always proceed with the order.
Can someone guide me on how to ensure this functionality is restricted to only the "Add to Cart" button, while the "Order Now" button bypasses the duplicate check?
I have written the following Script Include for this functionality:
And the onSubmit client script: