SharePoint Learning
Login
Signup Free
User Login
Close
 
 
Keep me logged in on this computer
Signup for a FREE user account
Close
Email
Password
Designation (optional)
First Name
Last Name
Headline (optional)
Online SharePoint training videos and articles
Price: FREE

Getting workflow instance info for a SharePoint list programmatically

By Lin Zhang on 18 June 14

Use SPWorkflowCollection and SPWorklfow to get workflow instance info for a SharePoint list programmatically.

Namespace:

using Microsoft.SharePoint.Workflow;

Code:

string subsiteName = "crm"; // crm is a sub-site
using (SPSite currentSite = new SPSite(SPContext.Current.Site.ID))
{
      using (SPWeb currentWeb = currentSite.OpenWeb(subsiteName))
      { 
             SPList myList = currentWeb.Lists["Training Records"]; // Traning Records is a list in crm site

             SPWorkflowCollection workflowCollection = new SPWorkflowCollection(myList);

             foreach (SPWorkflow workflow in workflowCollection)
             {
                      int itemID = Convert.ToInt32(workflow.ItemId); 
                      string instanceID = Convert.ToString(workflow.InstanceId);
                      string workflowStatus = "<a href=\"/"+subsiteName+"/_layouts/WrkStat.aspx?WorkflowInstanceID=" + instanceID + "\">In Progress</a>";

	              // Your codes here...
                      // Other properties: http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.workflow.spworkflow_properties%28v=office.15%29.aspx

              }

       }
}

Other properties for SPWorkflow (Reference: http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.workflow.spworkflow_properties%28v=office.15%29.aspx):

  Name Description
Public property AssociationId Gets the ID of the workflow association on which this workflow instance is based.
Public property Author Returns the ID of the user who initiated the workflow instance.
Public property AuthorUser Returns the user who initiated the workflow instance.
Public property CorrelationId  
Public property Created Gets the date and time when the workflow instance was created.
Public property HasNewEvents Gets a value that indicates whether the SPWorkflow has new events to be processed.
Public property HistoryList Gets the list to log workflow history events to for this workflow instance.
Public property HistoryListId Gets the list ID of the list to log workflow history events to for this workflow instance.
Public property InstanceId Gets the ID of this workflow instance.
Public property InternalState Gets the current internal state of the workflow instance.
Public property IsCompleted true if the workflow instance has completed; false if the workflow instance is still in progress.
Public property IsLocked true if the workflow instance is locked; false if it is not.
Public property ItemGuid Gets the ID of the item on which this workflow instance was created.
Public property ItemId Gets the list ID of the item on which this workflow instance was created.
Public property ItemName Gets the name of the SPListItem on which the SPWorkflow instance was created.
Public property ListId Gets the ID of the list on which this workflow instance was created.
Public property Modifications Gets a collection of the workflow modifications currently in scope for this workflow instance.
Public property Modified Gets the date and time of the last modification to the workflow instance.
Public property OwnerUser Gets the owner of the SPWorkflowTemplate on which this SPWorkflow instance is based.
Public property ParentAssociation Gets the workflow association on which the workflow instance is based.
Public property ParentItem Gets the list item on which this workflow instance was created.
Public property ParentList Gets the list on which this workflow instance was created.
Public property ParentWeb Gets the SharePoint site on which this workflow instance was created.
Public property SiteId Gets the ID of the site collection on which this workflow instance was created.
Public property StatusText A string status of the workflow
Public property StatusUrl Gets the URL of a custom workflow status page for the SPWorkflow.
Public property StatusValue A integer status of the workflow. Corresponds with SPWorkflowStatus
Public property TaskFilter Gets or sets the filter criteria applied to the workflow task collection, such as to whom the workflow is assigned, and the workflow state.
Public property TaskList Gets the workflow task list.
Public property TaskListId Gets the ID of the workflow task list.
Public property Tasks Gets the collection of workflow tasks for this workflow instance.
Public property VisibleParentItem Gets a value that represents whether the item the workflow is running on is visible.
Public property WebId Gets the ID of the SharePoint site on which this workflow instance was created.
Public property Xml Returns a string that represents the workflow instance in XML format.

Comments:

No comments.

Copyright © SharePointLearning.net.au. All Rights Reserved | Contact Us

Powered by DigiLife Studio