Bug reports Found a bug? Post it here please.
Version 7.x > Bug reports > Custom Scheduled Task not running under selected User Context View modes: 
User avatar
Certified Developer v6
Certified Developer v6
Dave - 1/20/2014 3:08:07 PM
   
Custom Scheduled Task not running under selected User Context
Hi,

I've written a custom Scheduled Task (ITask). I am finding that setting the User Context dropdown on the Task UI does not result in the task code having that user set under CMSContext.CurrentUser. Am I missing something, or is there a proper way to accomplish this?

Thanks,
Dave

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 1/21/2014 1:42:39 AM
   
RE:Custom Scheduled Task not running under selected User Context
Hi Dave,

Thank you for your message.

I believe that this is caused by the fact the the CMS.Context.CurrentUser is always holding a currently logged user. The setting in Scheduled task is to set in which context should the task run, not to override the CMS.Context.CurrentUser (that will always be you as a logged user). So you should alter your code in order to make it right, I hope this will help you in understanding the problem.

Kind regards,
Richard Sustek

User avatar
Certified Developer v6
Certified Developer v6
Dave - 1/21/2014 8:29:13 AM
   
RE:Custom Scheduled Task not running under selected User Context
Hi Richard,

Thanks very much for your response. Do you have any examples of a custom task that implements this functionality?

Thanks,
Dave

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/21/2014 1:59:32 PM
   
RE:Custom Scheduled Task not running under selected User Context
In your custom code simply set the TaskInfo.TaskUserId property.
public string Execute(TaskInfo ti)
{
ti.TaskUserID = 45; // or whatever user id you want to use
// execute your switch statement and code....
}

User avatar
Certified Developer v6
Certified Developer v6
Dave - 1/30/2014 1:54:44 PM
   
RE:Custom Scheduled Task not running under selected User Context
Makes sense - thanks FroggEye!