Create a Custom Workflow - Example

In Master Data Services, when you create a custom workflow class library, you create a class that implements the Microsoft.MasterDataServices.WorkflowTypeExtender.IWorkflowTypeExtender interface. This interface includes one method, StartWorkflow, that is called by SQL Server MDS Workflow Integration Service when a workflow starts. The StartWorkflow method contains two parameters: workflowType contains the text you entered in the Workflow type text box in Master Data Manager, and dataElement contains metadata and item data for the item that triggered the workflow business rule.

Custom Workflow Example

The following code example shows how you how to implement the StartWorkflow method to extract the Name, Code, and LastChgUserName attributes from the XML data for the element that triggered the workflow business rule, and how to call a stored procedure to insert them into another database. For an example of the item data XML and an explanation of the tags it contains, see Custom Workflow XML Description (Master Data Services).

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.IO;  
using System.Data.SqlClient;  
using System.Xml;  

using Microsoft.MasterDataServices.Core.Workflow;  

namespace MDSWorkflowTestLib  
    public class WorkflowTester : IWorkflowTypeExtender  
        #region IWorkflowTypeExtender Members  

        public void StartWorkflow(string workflowType, System.Xml.XmlElement dataElement)  
            // Extract the attributes we want out of the element data.  
            XmlNode NameNode = dataElement.SelectSingleNode("//ExternalAction/MemberData/Name");  
            XmlNode CodeNode = dataElement.SelectSingleNode("//ExternalAction/MemberData/Code");  
            XmlNode EnteringUserNode = dataElement.SelectSingleNode("//ExternalAction/MemberData/LastChgUserName");  

            // Open a connection on the workflow database.  
            SqlConnection workflowConn = new SqlConnection(@"Data Source=<Server instance>; Initial Catalog=WorkflowTest; Integrated Security=True");  

            // Create a command to call the stored procedure that adds a new user to the workflow database.  
            SqlCommand addCustomerCommand = new SqlCommand("AddNewCustomer", workflowConn);  
            addCustomerCommand.CommandType = System.Data.CommandType.StoredProcedure;  
            addCustomerCommand.Parameters.Add(new SqlParameter("@Name", NameNode.InnerText));  
            addCustomerCommand.Parameters.Add(new SqlParameter("@Code", CodeNode.InnerText));  
            addCustomerCommand.Parameters.Add(new SqlParameter("@EnteringUser", EnteringUserNode.InnerText));  

            // Execute the command.  


See Also

Create a Custom Workflow (Master Data Services)