cancel
Showing results for 
Search instead for 
Did you mean: 

Adding SpecialPrices return DateRange Invalid

Former Member
0 Kudos

Hi,

I am trying to programmatically add SpecialPrices and I got the error "Date Range Invalid" error. Below is my code:

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

sp.AutoUpdate = SAPbobsCOM.BoYesNoEnum.tYES;

sp.CardCode = "1903";

sp.ItemCode = "T123";

sp.Price = 58;

sp.PriceListNum = 1;

sp.SpecialPricesDataAreas.SetCurrentLine(0);

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

sp.SpecialPricesDataAreas.Discount = 15;

sp.SpecialPricesDataAreas.PriceCurrency ="USD";

sp.SpecialPricesDataAreas.PriceListNo = 1;

sp.SpecialPricesDataAreas.SpecialPrice = 55;

sp.SpecialPricesDataAreas.DateFrom = new System.DateTime(2005,11,1,0,0,0,0);

sp.SpecialPricesDataAreas.Add();

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Discountin = 14;

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

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Quantity = 10;

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SpecialPrice = 54;

sp.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Add();

int retval = sp.Add();

int errCode;

string errMsg;

if(0!=retval){

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

Console.WriteLine(errMsg);

}

else{

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

}

Thank you in advance.

Sunny

Message was edited by: sansanee hanveerawong

Accepted Solutions (1)

Accepted Solutions (1)

barend_morkel2
Active Contributor
0 Kudos

Hi Sansanee,

Special Prices functions for a date range. You need a from date and a to date.

In your code you've got a "from date":

sp.SpecialPricesDataAreas.DateFrom = StartDate

But you need a "to date":

sp.SpecialPricesDataAreas.Dateto = EndDate

Former Member
0 Kudos

Hi Barend,

Thank you for your reply but even if I added this line to add Dateto, it still didn't work.

sp.SpecialPricesDataAreas.Dateto = new System.DateTime(2005,12, 31,0,0,0,0);

It still returned the same error: "Invalid Date Range". Do you happen to know if there is any setting in SBO that specify how many days interval the special prices should be in effect or there is some sort of business rule some where? I am stumped with this problem and would greatly appreciate any help.

Thank you in advance,

Sunny

barend_morkel2
Active Contributor
0 Kudos

Sansanee,

There is no setting in SBO that specify how many days interval the special prices should be in effect. It is completely configurable. make sure the date range you are entering fals within the configured posting periods as defined in general settings (under the administration tab)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Sansanee,

you get this problem if there already exists a special price for the same CardCode and ItemCode. You first have to delimit the preceding row with an end date smaller than your new start date, then you can add your new entry.

Hope, this will help you

Eduard

Former Member
0 Kudos

I'got the same problem,

Did you solved it anyway?

Thanks

Paolo