Jun 30, 2010
(0 votes)

CreatedBy Not Set When Jobs run on a Schedule – Oracle Error

I recently stumbled across a bug in EPiServer that relates directly to Oracle. It’s somewhat obscure, so I figured it would be a good idea to post how we dealt with it here…

When a page is created through the SDK’s DataFactory.Instance.Save method, EPiServer automatically sets CreatedBy to the person who is logged in and executing the code. So for manual page creation through the SDK, the following works just fine…

PageData myPage = EPiServer.DataFactory.Instance.GetDefaultPageData(
                      parent, "Standard page");
myPage.PageName = "My new page";
myPage.Property["MainBody"].Value = "<p>This is produced programmatically.</p>";
myPage.VisibleInMenu = false;
myPage.StartPublish = DateTime.Now.AddMinutes(-1);
DataFactory.Instance.Save(myPage, EPiServer.DataAccess.SaveAction.CheckIn, AccessLevel.NoAccess);

But when this is set up to be run in a job that is scheduled, the CreatedBy is set to NULL. For the vast majority of sites that run EPiServer on SQL Server, this isn’t an issue. But those sites that run on Oracle will find that, upon logging into their CMS, the application throws a lovely “Unable to Cast object of type ‘System.DBNull’ to type ‘System.String’.” error.




What’s happening here is that EPiServer is calling several FindPageActivities methods, and looking at the Activities associated with a particular user name. In this case, it sees that a page needs to be displayed, but it has NULL for CreatedBy. In SQL Server, an empty string is displayed. In Oracle, an exception is thrown.

This is a bug, and will likely be addressed by EPiServer at some later point.. but in the interim, a workaround needs to be found for those who might be experiencing this issue.

… which is where Ted Nyberg’s blog post came in. I went ahead and created a process account, checked if this was being run by a scheduled job or if it was running by a person, and then defaulted to a process account in a situation when no CurrentPrincipal.Identity.Name existed… this creates the page programmatically on a schedule and sets the default CreatedBy to whatever account you specify. Back in business, no oracle errors.

            public static string Execute()
                if (PrincipalInfo.CurrentPrincipal.Identity.Name == string.Empty)
                    PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("test_account");

                    int Records = GetRecords();
                    return "Content succesfully imported. " + Records + " blog comments entered into the system.";

Incidentally, if you do have this error and need to get rid of it.. you can either delete the pages that were created programmatically, re-save and publish them (which will set the CreatedBy value to your name) or you can edit tblWorkPage where FKPageID=the new page ID and change the ChangedByName to your username.. any of these will fix it.

Special thanks to Deane Barker for helping to come up with the solution to this problem

Jun 30, 2010


Sep 21, 2010 10:33 AM

Good blog! Nice work by both you and Deane. :)
/ Jeff Wallace

Please login to comment.
Latest blogs
Customizing Property Lists in Optimizely CMS

Generic property lists is a cool editorial feature that has gained a lot of popularity - in spite of still being unsupported (officially). But if y...

Allan Thraen | Oct 2, 2022 | Syndicated blog

Content Delivery API – The Case of the Duplicate API Refresh Token

Creating a custom refresh provider to resolve the issues with duplicate tokens in the DXC The post Content Delivery API – The Case of the Duplicate...

David Lewis | Sep 29, 2022 | Syndicated blog

New Optimizely certifications - register for beta testing before November 1st

In January 2023, Optimizely is making updates to the current versions of our certification exams to make sure that each exam covers the necessary...

Jamilia Buzurukova | Sep 28, 2022

Optimizely community meetup - Sept 29 (virtual + Melbourne)

Super excited to be presenting this Thursday the 29th of September at the Optimizely community meetup. For the full details and RSVP's see the...

Ynze | Sep 27, 2022 | Syndicated blog