Try our conversational search powered by Generative AI!

Create new promotion campaign in initialization module. SalesCampaignFolder.CampaignRoot is null.


I am trying to create a new campaign for a new promotion in a initialization module, but every time I try to run it, SalesCampaignFolder.CampaignRoot is null. Below is my current code.

_contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
_campaign = _contentRepository.GetDefault<SalesCampaign>(SalesCampaignFolder.CampaignRoot);

Thanks for any help.

Mar 13, 2019 16:40

Hi - Make sure your initialization module depends on EPiServer.Commerce.Initialization.InitializationModule 

Inside the context of Initialize(InitializationEngine context), you don't have to use ServiceLocator, use 

context.Locate.Advanced instead 

Mar 14, 2019 10:09

Ah I see, I was using the Framework InitializationModule for the module dependency. That seemed to do the trick. Thanks!

Mar 14, 2019 14:17
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.