cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPQ: Quote item isn't deleted automatically.

former_member611643
Participant
0 Kudos

Hi, friends.

I've written a Global Script which should add product "Delivery" to a Quote if "Total" is less than 15$ and delete "Delivery" if "Total" is more than 15$.

At the moment, adding works fine, but not deleting. When I add some new product to Quote and the "Total" is more than 15$ "Delivery" isn't deleted.

Total calculated according to the formula: Total = Total - Delivery_Price.

P.S: When I change the quantity of a product in Quote or when I reopen the Quote deleting works fine.

I'll be grateful for any useful feedback.


The Global Script code:

free_delivery_threshold = 15
query = SqlHelper.GetSingle("SELECT product_price AS price FROM products WHERE product_name like 'Delivery'")

delivery_price = query.price
if Quote.ContainsAnyProductType("Fast-food_cpq"):
   if ( Quote.Total.TotalAmount - delivery_price ) > free_delivery_threshold and Quote.ContainsAnyProductByName('Delivery'):
       for item in Quote.MainItems:
           if item.ProductName == 'Delivery':
              item.Delete()
              Quote.Messages.Add("Order amount is more than {0}$. Free delivery!".format(free_delivery_threshold))
              Quote.Save()

   if ( Quote.Total.TotalAmount - delivery_price ) <= free_delivery_threshold and not Quote.ContainsAnyProductByName('Delivery'):
       Quote.AddItem('Delivery_cpq')
       Quote.Messages.Add("Order amount is less than {0}$. Paid delivery!".format(free_delivery_threshold))
       Quote.Save()


Global Script Events:


Quote Total less than 15$:


Quote Total more than 15$:

Accepted Solutions (0)

Answers (1)

Answers (1)

nikhilwalsetwar
Contributor
0 Kudos

Hi Sigy,
Please add below code after Quote.Save() method in first if loop.

Quote.Reconfigure();

So final code would look like,

for item in Quote.MainItems:
           if item.ProductName == 'COILS':
              item.Delete()
              Quote.Save()
              Quote.Reconfigure()

Hope this will solve your problem.

Best,

Nikhil