Results 1 to 4 of 4

Thread: How to pass parameters to a workflow

  1. #1
    Join Date
    Jan 2011
    Posts
    24

    How to pass parameters to a workflow

    I must establish a workflow for one of my Sharepoint web application. (I say that I totally started there). I chose Visual Studio 2010 to create it because it suits my needs more. However, I have a concern. The launch of the workflow must be performed by receiving an input parameter (ie the identifier of an object from my base). This identifier will certainly recovered from a graphics controller interface of the web site. ("Certainly" because I have not yet done ...). Someone tell me how can I pass a parameter input to a workflow please?

  2. #2
    Join Date
    May 2008
    Posts
    913

    Re: How to pass parameters to a workflow

    To do this, there are two ways: through the use of parameters or by the unleashing of events. The parameters are the property of the class that represents the workflow, which can then be used both by the activities in the workflow from the host. To use the events, however, create custom activity to serve as a source of external data and information within the workflow steps. In today's article, we focus only on the use of parameters. We said that to add the parameters, just enter their property in the class that represents the workflow, then, that of taking our first example, this becomes:

    workflow1.cs
    Code:
    public sealed partial class Workflow1 : SequentialWorkflowActivity
    
    {
    
         private string username;
    
         public string Username
    
         {
    
              get { return username; }
    
              set { username = value; }
    
         }
    
         public Workflow1()
    
         {
    
              InitializeComponent();
    
         }
    
         private void helloWorldCodeActivity_ExecuteCode(object sender, EventArgs e)
    
         {
    
              Console.WriteLine("\nHello {0} !", Username);
    
         }
    
    }

  3. #3
    Join Date
    Nov 2008
    Posts
    1,022

    Re: How to pass parameters to a workflow

    Now when the workflow is instantiated, the properties are the parameters that must be filled with information. What to do? Simple. One of the overloads of CreateWorkflow method (a method used to return an instance of the workflow to be run) in addition to the type of workflow, also provides a generic object type <string, object> Dictionary. Here, this object will contain all key-value pairs useful for passing data to the properties of the workflow, where the key of each pair will be the name of the property to be valued.

  4. #4
    Join Date
    Nov 2008
    Posts
    1,185

    Re: How to pass parameters to a workflow

    Here I have provided the code for you by using which you can create the program.cs file that would be helping you to send the parameters to the workflow file.

    program.cs
    Code:
    class Program
    
    {
    
         static void Main(string[] args)
    
         {
    
              using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
    
              {
    
                   AutoResetEvent waitHandle = new AutoResetEvent(false);
    
                   workflowRuntime.WorkflowCompleted +=
    
                             delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
    
                   workflowRuntime.WorkflowTerminated +=
    
                             delegate(object sender, WorkflowTerminatedEventArgs e)
    
                   {
    
                        Console.WriteLine(e.Exception.Message);
    
                        waitHandle.Set();
    
                   };
    
                   Console.Write("Insert your name: ");
    
                   Dictionary<string, object> parameters = new Dictionary<string, object>();
    
                   parameters.Add("Username", Console.ReadLine());
    
                   Type t = typeof(HelloWorkflow.Workflow1);
    
                   WorkflowInstance instance = workflowRuntime.CreateWorkflow(t, parameters);
    
                   instance.Start();
    
                   waitHandle.WaitOne();
    
                  Console.WriteLine("\n\n");
    
                   Console.WriteLine("Press any key to exit ...");
    
                   Console.Read();
    
              }
    
         }
    
    }

Similar Threads

  1. Replies: 9
    Last Post: 30-08-2010, 04:57 PM
  2. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  3. Pass Parameters To A Popup in Java
    By Adrina_g in forum Software Development
    Replies: 4
    Last Post: 23-02-2010, 09:01 PM
  4. How to Pass Parameters to Functions
    By super soaker in forum Software Development
    Replies: 3
    Last Post: 31-12-2009, 12:16 PM
  5. How to Pass Parameters via URL
    By Paramartha in forum Software Development
    Replies: 4
    Last Post: 23-09-2009, 06:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,886,570.26115 seconds with 17 queries