Restrict "Add to Cart" adding same Item into cart for same requested for
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 01:53 AM
Hi,
I have a requirement where I have to restrict the Add to Cart option -
- If the Requested For person's USER ID is already added to Cart, in that case, an error message should display saying "Item already added into cart".
- Restrict Add to cart limit upto 10
Thanks,
Piyush Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 02:33 AM
Hi @Piyush27
- To achieve the first requirement of restricting the "Add to Cart" option if the requested user's ID is already added to the cart, you can create a business rule.
1. Go to "Business Rules" in the ServiceNow menu and click on "New".
2. Give the rule a name such as "Prevent duplicate items in cart".
3. Set the "When to run" field to "Before" and select the "Insert" and "Update" options.
4. In the "Advanced" section, add the following script:
5. Save the business rule.
This script will check if the requested user's ID is already in the cart and prevent the item from being added to the cart if it is. It will also show an error message to the user.
- Likewise, to achieve the second requirement of restricting the "Add to Cart" limit up to 10, you can create another business rule in ServiceNow.
1. Go to "Business Rules" in the ServiceNow menu and click on "New".
2. Give the rule a name such as "Limit items in cart".
3. Set the "When to run" field to "Before" and select the "Insert" option.
4. In the "Advanced" section, add the following script:
5. Save the business rule.
This script will count the number of items in the cart and prevent the current item from being added to the cart if the cart already has 10 items. It will also show an error message to the user.
Please mark correct/helpful, if your query is addressed and/or answered.
Thanks,
Vamshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 03:50 AM
Hi @Rao Vamshi , On which table you wrote business rule. Can you plz mention here. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 04:33 AM
@Rao Vamshi Thanks it is really helpful, but can we approach any another way actually i don't want to use business rule as of now. Is there any another way?