cancel
Showing results for 
Search instead for 
Did you mean: 

Updating SpecialPrices returned Invalid Date Range

Former Member
0 Kudos
522

Hi,

I am trying to update special prices but I keep getting Invalid Date Range even though the posting period is of 2006. I would apprecaite if anyone can point me out on what i have done wrong.

Below is my code in C#:

public static void UpdateSpecialPrices(B1DataConnection conn) {

SAPbobsCOM.SpecialPrices sp = (SAPbobsCOM.SpecialPrices) conn.InternalConnection.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSpecialPrices);

string cardCode = "C20";

string itemCode = "T1";

bool isFound = sp.GetByKey(itemCode, cardCode);

if(false == isFound){

Console.WriteLine("Special prices for Itemcode {0} and CardCode not found", itemCode, cardCode);

}

sp.Price = 60;

sp.PriceListNum = 1;

sp.SpecialPricesDataAreas.SetCurrentLine(0);

sp.SpecialPricesDataAreas.AutoUpdate = SAPbobsCOM.BoYesNoEnum.tYES;

sp.SpecialPricesDataAreas.Discount = 2;

sp.SpecialPricesDataAreas.PriceCurrency ="USD";

sp.SpecialPricesDataAreas.PriceListNo = 1;

sp.SpecialPricesDataAreas.SpecialPrice = 56;

sp.SpecialPricesDataAreas.DateFrom = new System.DateTime(2006,1,2,0,0,0,0);

sp.SpecialPricesDataAreas.Dateto = new System.DateTime(2006,1,16,0,0,0,0);

sp.SpecialPricesDataAreas.Add();

sp.SpecialPricesDataAreas.SetCurrentLine(1);

sp.SpecialPricesDataAreas.AutoUpdate = SAPbobsCOM.BoYesNoEnum.tYES;

sp.SpecialPricesDataAreas.Discount = 5;

sp.SpecialPricesDataAreas.PriceCurrency ="USD";

sp.SpecialPricesDataAreas.PriceListNo = 1;

sp.SpecialPricesDataAreas.SpecialPrice = 58;

sp.SpecialPricesDataAreas.DateFrom = new System.DateTime(2006,2,5,0,0,0,0);

sp.SpecialPricesDataAreas.Dateto = new System.DateTime(2006,2,20,0,0,0,0);

sp.SpecialPricesDataAreas.Add();

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SetCurrentLine(0);

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Discountin = 3;

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.PriceCurrency ="USD";

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Quantity = 25;

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Add();

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SetCurrentLine(1);

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Discountin = 5;

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.PriceCurrency ="USD";

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Quantity = 45;

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Add();

int retval = sp.Update();

int errCode;

string errMsg;

if(0!=retval){

conn.InternalConnection.GetLastError(out errCode, out errMsg);

Console.WriteLine(errMsg);

}

else{

Console.WriteLine("updating special price successfully");

}

}

Thanks a lot in advance,

Sunny

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

I've ran into a similar problem in 2005A PL43, and realized that after SPP.GetByKey(ItemCode, CardCode) returns false, I need to release and re-instantiate the SPP object, meaning something like that:


          If SPP.GetByKey(ItemCode, CardCode) Then
            ' SPP record exists for this item and price list, need to Update SPP1
            SPP.SpecialPricesDataAreas.Add()
            SPP.SpecialPricesDataAreas.DateFrom = dDateFrom
            SPP.SpecialPricesDataAreas.Dateto = dDateTo
            SPP.SpecialPricesDataAreas.AutoUpdate = SAPbobsCOM.BoYesNoEnum.tYES
            SPP.SpecialPricesDataAreas.PriceListNo = PriceListNo
            SPP.SpecialPricesDataAreas.SpecialPrice = SpecialPrice
            SPP.SpecialPricesDataAreas.PriceCurrency = Currency
            SPP.SpecialPricesDataAreas.UserFields.Fields.Item("U_Campaign").Value = Campain_DocEntry
            If SPP.Update() <> 0 Then Throw New SBO_DI_Exception
          Else
            ' SPP record does not exist for this item and price list, need to add OSPP and SPP1

            ' added in PL43 - reinstantiate the SPP object
            System.Runtime.InteropServices.Marshal.ReleaseComObject(SPP) 'Needed to release the SAP COM object
            SPP = Nothing
            SPP = DirectCast(SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSpecialPrices), SAPbobsCOM.SpecialPrices)

            SPP.ItemCode = ItemCode
            SPP.CardCode = CardCode
            SPP.PriceListNum = PriceListNo
            SPP.SpecialPricesDataAreas.DateFrom = dDateFrom
            SPP.SpecialPricesDataAreas.Dateto = dDateTo
            SPP.SpecialPricesDataAreas.AutoUpdate = SAPbobsCOM.BoYesNoEnum.tYES
            SPP.SpecialPricesDataAreas.PriceListNo = PriceListNo
            SPP.SpecialPricesDataAreas.SpecialPrice = SpecialPrice
            SPP.SpecialPricesDataAreas.PriceCurrency = Currency
            SPP.SpecialPricesDataAreas.UserFields.Fields.Item("U_Campaign").Value = Campain_DocEntry
            If SPP.Add() <> 0 Then Throw New SBO_DI_Exception
          End If
        Next

The releasing of the object was not necessary when I used PL27.

Answers (0)