Set PriceList by adding a new Item by Code
Sebastian Schweer
Hallo,i have the following Problem:
I want to add an Article into the Master Data by Code.
This works well.
But how can i set a chosen PriceList for the new Item?
If i set a price and a Currency for the new item, its added by default into PriceList One.
And if i try the following Line, i got an Error:
oItem.PriceList.PriceList = 2;
Error: "Property or indexer 'SAPbobsCOM.IItems_Prices.PriceList' cannot be assigned to -- it is read only (CS0200)"
Thanks for your Help,
Sebastian
Bastian Hofmeister
Hi Sebastian,You have to create another object to add/update the price of an item in a pricelist.
I did it directly with the DI API, but the code is quite similar.
SAPbobsCOM.Items oItem = (SAPbobsCOM.Items)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
SAPbobsCOM.Items_Prices oItemPrice;
oItem.GetByKey("10000");
oItemPrice = oItem.PriceList;
oItemPrice.SetCurrentLine(0); // first PriceList
oItemPrice.Price = 44.5;
oItem.Update();
HTH
Basti
Sebastian Schweer
Hallo Basti,thanks a lot for your help.
Now I know to get over the oCompany Object and the Items_Prices Object.
For everybody else, here the final C# Code for Updating the Price Lists:
SAPbobsCOM.Company oCompany = customize.B1Connector.GetB1Connector().Company;
SAPbobsCOM.Items oItem = (SAPbobsCOM.Items) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
SAPbobsCOM.Items_Prices oItemPrice;
oItem.GetByKey("111021"); // Item Code of the Object
oItemPrice = oItem.PriceList;
oItemPrice.SetCurrentLine(0); // Price List 1
oItemPrice.Currency = "EUR";
oItemPrice.Price = 100;
oItem.Update();
oItemPrice.SetCurrentLine(1); // Price List 2
oItemPrice.Currency = "USD";
oItemPrice.Price = 200;
oItem.Update();
oItemPrice.SetCurrentLine(2); // Price List 3
oItemPrice.Currency = "R$";
oItemPrice.Price = 500;
oItem.Update();
Best Regards,
Sebastian
0
Please sign in to leave a comment.
Comments
0 comments