Question

I am working on a SharePoint web part that would approve selected Nintex Workflow Tasks. It would be simple form listing Nintex Workflow Tasks (check-boxes for the ones that need to be approved). Does anyone have an example how to get Nintex Workflow Tasks in a site collection? I guess that CAML query would be used for this.

Thank you,

Jakub

No correct solution

OTHER TIPS

Since you have to get the tasks from different sub sites in a site collection, you will have to use SPSiteDataQuery. You can use the list template for workflow task and give webs scope as "SiteCollection" as you need tasks from all the sub sites. You can write your caml query condition to filter out tasks.

SPSiteDataQuery query = new SPSiteDataQuery();

               // Query all Web sites in this site collection.
               query.Webs = "<Webs Scope=\"SiteCollection\">";
//Ask for all lists created from the tasks template.
               query.Lists = "<Lists ServerTemplate=\"107\" />";

Here is the list of all list template ids http://mirusp2010.blogspot.in/2013/03/list-template-id.html

If you have created custom list template for class you can specify that ID.The datatable returned by the SPSiteDataQuery will have information regarding the sub site where this task is from , id of the task etc. You can create a custom control with checkboxes to display the tasks and add functionality to approve that task.

At least two approaches could be considered for web part implementation

Query based web part

Since the scope is a site collection, SPSiteDataQuery class should be utilized.

Example: return Nintex tasks from site collection

        /// <summary>
        /// Retrieve Nintex Tasks from site collection  
        /// </summary>
        /// <param name="siteUrl"></param>
        /// <returns></returns>
        public static DataTable GetNintexTasksResult(string siteUrl)
        {
            using (var site = new SPSite(siteUrl))
            {
                SPSiteDataQuery query = new SPSiteDataQuery();

                query.Lists = "<Lists ServerTemplate=\"107\" />";
                query.Query = "<Where>" +
                              "   <Or>" +
                              "      <Eq>" +
                              "         <FieldRef Name='ContentType' />" +
                              "         <Value Type='Text'>Nintex Workflow Task</Value>" +
                              "      </Eq>" +
                              "      <Eq>" +
                              "         <FieldRef Name='ContentType' />" +
                              "         <Value Type='Text'>Nintex Workflow Multi Outcome Task</Value>" +
                              "      </Eq>" +
                              "   </Or>" +
                             "</Where>";
                query.Webs = "<Webs Scope=\"SiteCollection\" />";

                return site.RootWeb.GetSiteData(query);
            }
        }

Search based web part

Steps:

  • You will need to create a custom Managed Property in your Search Service Application that maps to the crawled property ows_ContentType

  • Then you can construct keyword query: ContentTypeName:"Nintex Workflow Multi Outcome" OR ContentTypeName:"Nintex Workflow Task"

Please refer Building Search Queries for a more details

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top