Skip to main content

Hello There,


I would like to find out if it is possible to create a workflow dynamically?


 


Regards


Amarnath


Hello There,


I would like to find out if it is possible to create a workflow dynamically from code?



Can you elaborate on what you are trying to accomplish?  Describe the situation?


Hello There,


Here is my requirement.


Is it possible to call a workflow multiple times.


The scenario is as follows:


I have to fetch some data from the database and for each row i have to send a notification to owner. The Owner has to approve in a selected time. If he does not reply, i have to escalate the approval.


 


Is it possible to call a worflow multiple times from a main workflow.


 


Any Help will be appreciated.


 


 


Regards


Amarnath


Is it possible to call a workflow multiple times from code?


 


Regards


Amarnath


Yes, however it will create individual instances of that workflow.  each one seperate. Is that what you are looking for?


you would just need to write some code that iterated through your source of items, and do a for each type operation. Here is some sample code that starts a new processes and sets some data fields


 
using System;
using System.Collections.Generic;
using System.Text;
using SourceCode.Hosting.Client;
using SourceCode.Workflow.Client;
 
namespace K2Samples
{
    class WorkflowAccessingSample
    {
        public void SetDataFieldsStartProcess()
        {
            // TODO: Replace these placeholder values with values for your environment
            string _serverName = "blackpearl";
            string _user = "K2Student";
            string _domain = "DENALLIX";
            string _password = "K2pass!";
            string _processName = "K2WorkflowProject1Process1";
            string _name = "Total Cost";
            string _amount = "100";
            string _processFolio = "Project 1 Process 1";
 
            SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString =
                new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
 
            connectionString.Authenticate = true;
            connectionString.Host = "localhost";
            connectionString.Integrated = true;
            connectionString.IsPrimaryLogin = true;
            connectionString.Port = 5252;
            connectionString.UserID = _user;
            connectionString.WindowsDomain = _domain;
            connectionString.Password = _password;
            connectionString.SecurityLabelName = "K2"; //the default label
 
            Connection connection = new Connection();
 
            try
            {
                //open connection to K2 server
                connection.Open(_serverName, connectionString.ToString());
 
                //create process instance
                ProcessInstance processInstance = connection.CreateProcessInstance(_processName);
 
                //populate data fields
                processInstance.DataFieldso"Name"].Value = _name;
                processInstance.DataFieldsÂ"Amount"].Value = _amount;
 
                //set process folio
                processInstance.Folio = _processFolio + System.DateTime.Today.ToString();
 
                //start the process
                connection.StartProcessInstance(processInstance, false);
 
                Console.WriteLine("Name: " + processInstance.DataFieldsD"Name"].Value);
                Console.WriteLine("Amount: " + processInstance.DataFields "Amount"].Value);
                Console.WriteLine("Folio :" + processInstance.Folio.ToString());
                Console.WriteLine("ID: " + processInstance.ID.ToString());
                Console.ReadLine();
             }
 
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
 
            finally
            {
                // close the connection
                connection.Close();
            }
        }
    }
}


Yes Chris


This is what I am looking for.


So I can have just one workflow and i can create multiple instances of it.


Thank You


Regards


Amarnath


You bet


Hello Chris,


I have a doubt regarding this method.


If I call multiple instances of a workflow from a parent workflow and make is synchronous so that the parent has to wait till it hears from all the child instances, how would i keep track if all the instances have responded or not.


Also, how would the child instances behave? Are they synchronous or asynchronous.


 


 


Regards


Amarnath


Reply