cancel
Showing results for 
Search instead for 
Did you mean: 

Price List Items Update - DI API

Former Member
0 Kudos

Can anyone show me how I go about updating price list items using the DI API?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello

In DI Price lists can be updated via items, so steps would be followed:

1. Get the Item using getbykey

2. Locate the price list by number in a loop

3. update the price of the price list

4. update the item record

here is a simple code for this in c#

Variables:

itemcode = item number type String

price = item new price in the price list, type double

scurrency = currency of the price type string

spurchasepricelist = price list number you would like to update type integer


 SAPbobsCOM.Items oMM = null;
 oMM = (SAPbobsCOM.Items)globalD.oCompany.GetBusinessObject(BoObjectTypes.oItems);
 int lretcode = 0;
if (oMM.GetByKey(itemcode))
                    {
                        bool need2update = false;
                        for (int p = 0; p < oMM.PriceList.Count; p++)
                        {
                            oMM.PriceList.SetCurrentLine(p);
                            if (oMM.PriceList.PriceList.ToString() == spurchasepricelist)
                            {
                                price = Convert.ToDouble(oRs.Fields.Item(spuchasepricefield).Value);
                                oMM.PriceList.Price = price;
                                oMM.PriceList.Currency = scurrency;
                                need2update = true;
                                break;
                            }
                        }
                        if (need2update)
                        {
                            lretcode = oMM.Update();
                            if (lretcode != 0)
                                throw new Exception(string.Format("(pricelist){0}-{1}", globalD.oCompany.GetLastErrorCode(), globalD.oCompany.GetLastErrorDescription()));
                        }
                    }

Regards

János