cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPQ Quote 2.0 - How to add Item on quote via Custom Action using Python script?

760

Dear SAP-Community,

I am currently using Quote 2.0. I would like to create a Quote Table with a Custom Action called “Add Product”. By this action I want to add selected products from the table to the quote.

To do so I want to use a python script to create the custom action (Add Product) as below:

quoteTable = context.Quote.QuoteTables['Accessory_N']
for quoteRow in quoteTable.Rows:
    if quoteRow['Select_Product']:
        itemsAdded = context.Quote.AddItem('Accessory_N_cpq')
        for item in itemsAdded:
            if not item.PartNumber:
                item.PartNumber = str(quoteRow['Part_Number'])
                item.Description = str(quoteRow['Description'])
                item.ListPrice = quoteRow['Price']
                item.Cost = quoteRow['Cost']
context.Quote.Calculate()

But it shows the errors:

Line 4: AddItem() takes exactly 2 arguments (1 given)

Line 11: Calculate() takes exactly 1 argument (0 given)

How must the code snippet look like to add product to a quote based on system id or part number?

Look forward to your Answers.

Best Regards

Nuzat

Accepted Solutions (0)

Answers (1)

Answers (1)

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos

nuzatantora

you can use this in your script and loop from your quote table.
ProductHelper.CanBeAddedToQuote('1234')
0 Kudos

Hi yoganandamuthaiah,

Thank you so much for your response. Unfortunately I could not solve the issue with this suggestion. I think ProductHelper.CanBeAddedToQuote('1234') determines whether the product can be added to a quote or not, but not actually add the product to the quote.

source: https://help.sap.com/doc/94be872409ad4f7b902b6bd474c70cae/2105/en-US/html/4c110394-1d85-0241-cef4-a3...

I had found the method named AddItem which is responsible for adding a product to a quote, but I do not understand how it should be written. As it shows the javascript and other options to write but there is no python option available.

source: https://help.sap.com/doc/94be872409ad4f7b902b6bd474c70cae/2105/en-US/html/598345de-54e5-d213-e290-1b...

Best regards

Nuzat

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos
ProductHelper.CreateProduct('productsystemId').AddToQuote(1)   ## Simple Product Straight forward

nuzatantoraUse this above code for adding to quote.

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos
nuzatantora

If this is resolved, can you close this thread ?