Try our conversational search powered by Generative AI!

Setting schedule on promotion from code



Trying to set a different schedule for a promotion/ItemDiscount in code. 

For example.

            promotion.Schedule = new PromotionSchedule
                ValidFrom = new DateTime(2017, 04, 20),
                ValidUntil = new DateTime(2017, 04, 23),
                CampaignLink = promotion.ParentLink,
                UseCampaignDate = false

The Promotion gets saved and shows up in epi, and "UseCampaignDate" seems to be set correctly, but the validfrom and until are empty so the discount acts as "Expired".

Am I missing something?


Edited, Apr 21, 2017 9:47

Seems that the promotion needed to be saved to database before schedule could be set.

So first save the promotion, then set the schedule and then save again.

Apr 21, 2017 10:10

PromotionSchedule is just a BlockData, so you should not have to save the Promotion first before setting it. But I think your code is not the way you should do it, you can just set it like this 

promotion.Schedule.ValidFrom = new DateTime(2017, 04, 20);
promotion.Schedule.ValidUntil = new DateTime(2017, 04, 23);
promotion.Schedule.UseCampaignDate = false;

without having to create a new instance of PromotionSchedule.



Apr 21, 2017 10:19

That did work as a charm :) Thanks!

Edited, Apr 21, 2017 10:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.