Try our conversational search powered by Generative AI!

GetChildren not working in scheduled task

Vote:
 

I have a scheduled task which is supposed to get the child pages, call them C1 and C2 from a pagereference, call it P, set in a dynamic property of the start page.

Getting the reference to P always works. However, when GetChildren is called with P as argument, the results are a bit unpredictible. It seems that if I trigger the job manually the expected C1 and C2 are returned. When the job runs scheduled it returns no children.

If I use GetDescendents instead I get the pagelinks of C1 and C2 (there is nothing more under P). I can use GetPage and get C1 and C2 and verify that their ParentLink is actually P.

I thought it might be an issue with language branch, but it seems to select the correct one even when running as a scheduled task. Any idea why this might be happening? I can work around it with GetDescendents, but I still wonder why it happens.

#30349
Jun 12, 2009 9:41
Vote:
 

Hi Magnus.

Which version of EPiServer are you running? Could there be an issue with access rights? http://world.episerver.com/Forum/Pages/Thread.aspx?id=28953&epslanguage=en

Scheduled jobs are runned as a Anonymous user. You could howerver use impersonate and run the job with a specified user. Check out Erik Nordins blog for an example: http://antecknat.se/blog/2009/03/04/scheduled-tasks-tips/.

Hope this helps.

Br, Tore

#30350
Jun 12, 2009 10:11
Vote:
 
Thank you for the tip Tore! I am using CMS 5 R2 SP1, so GetChildren should be insensitive to access rights, but for some reason it does not work. Using FindALLPagesWithCriteria as mentioned by the article solves my problem perfectly though. This is actually what EPiServer does in the PageArchiveJob.
#30352
Jun 12, 2009 10:50
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.