Try our conversational search powered by Generative AI!

HXH
HXH
Jun 30, 2010
  5333
(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.

 

image

 

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

Comments

Sep 21, 2010 10:33 AM

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

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog