1

I'm working with Sitecore's scheduler to create news items programmatically. However, I'm stuck on a scenario where I need to retrieve the scheduler's last run date from the CMS.

Is there any way to get the scheduler's last run date from the CMS?

enter image description here

1
  • When you are trying to read Last run field from the schedule item, are you getting some issue. Can you please elaborate the issue a little more to suggest the appropriate solution.
    – ckhanna
    Commented Nov 6 at 6:40

3 Answers 3

3

Sitecore's API provides a straightforward way to check when a scheduled task was last executed using the scheduleItem.LastRun property. Here's how you can retrieve this information from your scheduled task:

public async void Execute(Item[] items, Sitecore.Tasks.CommandItem commandItem, Sitecore.Tasks.ScheduleItem scheduleItem)
{

       DateTime lastRunDate = scheduleItem.LastRun;
       Log.Info("Getting schedualr lastRunDate:" + lastRunDate, lastRunDate);
}

Hope this help!!

2
  • Thanks Praveen this code is working fine for me.
    – Abhishek
    Commented Nov 6 at 11:19
  • Glad to hear that Commented Nov 6 at 11:31
0

You can read the last run time for the scheduled task inside the command, using LastRun property as below.

using Sitecore;
using Sitecore.Data.Items;

public void Execute(Item[] items, Sitecore.Tasks.CommandItem commandItem, Sitecore.Tasks.ScheduleItem scheduleItem)
{
   var lastRunServerTime = DateUtil.ToServerTime(scheduleItem.LastRun);
}

Since the dates in Sitecore are stored in UTC Timezone, you can convert the time retrieved using LastRun property on the schedule item to server timezone using DateUtil extension as above.

Hope this helps!!! Let me know in case you have any queries.

0

You can read last run from schedule item which is passed as a parameter in Execute method in scheduler class

public void Execute(Sitecore.Data.Items.Item[] items, Sitecore.TasksCommandItem command, Sitecore.TasksScheduleItem schedule)
{
  var lastruntime = schedule.LastRun ;
}

Hope this helps !!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.