Staging Task API SelectTaskList WHERE condition

jeff McDaniel asked on January 12, 2017 22:38

When using CMS.Synchronizatio.StagingTaskInfoProvider.SelectTaskList() to retrieve a list of staging tasks, how would one structure the string "where" argument of this method to filter tasks based on task type. For example, if one wanted to only select the list of tasks for Publish Document task type (PUBLISHDOC). How would that look?

Something along these lines doesn't seem to be bringing back results.

DataSet tasks = StagingTaskInfoProvider.SelectTaskList(SiteContext.CurrentSiteID, targetServer.ServerID, "TaskType = 'PublishDoc'", null);

Thank you for any guidance you can provide.

Correct Answer

Anton Grekhovodov answered on January 13, 2017 07:40

Hi Jeff,

I think it's better to use helpers to build sql conditions in C# code for this methods, example:

var whereCondition = new WhereCondition().WhereEquals("TaskType", TaskHelper.GetTaskTypeString(TaskTypeEnum.PublishDocument));
var result =  StagingTaskInfoProvider.SelectTaskList(SiteContext.CurrentSiteID, targetServer.ServerID, whereCondition.ToString(true), null);

Maybe you don't see any results because there isn't a task with this type in your database. SelectTaskList method uses staging.task.selecttasklist query to get tasks. The body of this query is:

SELECT ##TOPN## ##COLUMNS## FROM Staging_Task WHERE (TaskSiteID IS NULL OR TaskSiteID = @TaskSiteID) AND (TaskID IN (SELECT SynchronizationTaskID FROM Staging_Synchronization WHERE SynchronizationServerID = @ServerID OR (@ServerID <= 0 AND (@TaskSiteID = 0 OR SynchronizationServerID IN (SELECT ServerID FROM Staging_Server WHERE ServerSiteID = @TaskSiteID AND ServerEnabled=1))))) AND (##WHERE##) ORDER BY ##ORDERBY##

You can manually execute this query in database with necessary parameters or you can just select rows from Staging_Task table to check:

SELECT COUNT(*) FROM Staging_Task WHERE TaskType = 'PUBLISHDOC'
0 votesVote for this answer Unmark Correct answer

Recent Answers


Zach Perry answered on January 12, 2017 22:53

Have you tried something like: var tasks = StagingTaskInfoProvider.GetTasks().Where("TaskType", QueryOperator.Equals, "PUBLISHDOC");

1 votesVote for this answer Mark as a Correct answer

jeff McDaniel answered on January 12, 2017 23:02

Unfortunately it doesn't look I have Where() extension method available on GetTasks(). Also GetTasks() has 5 required parameters for the version of CMS.Synchronization our project is using. Those methods must have been added in later versions of CMS.Synchronization.

The line of code provided in the question comes from how staging lists are retrieved in /CMSApiExamples/Tools/Staging/Default.aspx.cs. I wasn't able to find any relevant examples of the string WHERE condition.

Thanks!

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on January 12, 2017 23:12

First question is, did you include System.Linq? Although most Kentico's APIs are a Queriable object (so it's not actually retrieving all the objects then filter, but instead builds a Query), this one may not be and you may need to retrieve all and sort.

If all else fails and there isn't a native API method, you can always create a Custom Query that does what you need it to, grabs the task IDs that match that you can then loop through and retrieve. But i would think there would be a valid API for it...

1 votesVote for this answer Mark as a Correct answer

jeff McDaniel answered on January 12, 2017 23:20

Adding System.Linq didn't specially help or make .Where(). I was able to achieve retrieving multiple task type staging list items using the following:

DataSet tasks = StagingTaskInfoProvider.SelectTaskList(SiteContext.CurrentSiteID, targetServer.ServerID, "TaskType IN ('UPDATEDOC', 'PUBLISHDOC')", null);

It must have been the casing of the of take type that was preventing valid results from coming back.

Thanks!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 12, 2017 23:48

According to the API Documentation, SelectTaskList() method gets a list of tasks within a subtree. Whereas the GetTasks() method will get all the tasks. Unfortunately, it doesn't look like the GetTasks() method it utilizing the ObjectQuery syntax so it still has serveral input parameters, Where being one of them.

0 votesVote for this answer Mark as a Correct answer

jeff McDaniel answered on January 13, 2017 15:40 (last edited on January 13, 2017 15:59)

Thank you, that is a very clean implementation, that example definitely helped.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.