I think you need to set the access level in the save method as it is running without context.
Ex:
_contentRepository.Save(pageToUpdate as IContent, SaveAction.Publish, AccessLevel.NoAccess);
Hi Dileep,
I used this in my ContentEvents_PublishedContent event.
var pressReleaseDetailPageVarient = contentRepository.Get<PressReleaseDetailPage>(pressReleaseDetailPage.ContentLink);
var writablePage = pressReleaseDetailPageVarient.CreateWritableClone() as PressReleaseDetailPage;
writablePage.StopPublish = LastDateParser(writablePage.Created); // LastDateParser is my method to calculate the date
contentRepository.Save(writablePage, SaveAction.Default, AccessLevel.NoAccess);
Hi Dileep,
Gustav is correct here, I suspect the difference you're experiencing is based on whether you manually start the job or its started by the scheduler? Suprised you're not seeing anything in the logs though, it should be throwing an exception if it's failing to save.
You can either set the AccessLevel
as suggested or you could set a role when the job is triggered by the scheduler. This blog post provides some more details: https://world.episerver.com/blogs/Magnus-Rahl/Dates/2010/12/Run-a-scheduled-job-as-a-specific-role/
I have a need to create a scheduled job that updates expiry date on contents by certain duration. I created the job and below is the code that I have for updating the expiry date.
(pageToUpdate as IVersionable).StopPublish = expToUpdate; //expToUpdate is a extended date time value
_contentRepository.Save(pageToUpdate as IContent, SaveAction.Publish);
Funny thing is, this seems to work fine in local environment but this doesn't update the stop publish date in DXP. There is no error too. Can anyone point me to what am I missing here