I need to dynamically assign some destination users. And thus far I can’t find a solution.


Badge +2

Good day everyone,


 


I need your help please! I need to dynamically assign some destination users. And thus far I can’t find a solution.


 


Just to give you some background to my problem:


 


I have a custom front end/system that our users use to manage complaints.


Now when a request/complaint enters the flow, it lands in an activity that has a static role set for the destination users.


Those users then have an option to redirect the request to another user or to a department.


At that stage on the flow it moves to a new activity where it needs a new destination user, role or group.


 


At first we could only redirect to 1 user and that worked perfectly fine, I used a smart object(a sql stored proc that returns 1 username) to determine who the user was.


 


My problem now is that I have changed the stored proc/smart object to return more than one username if the user redirected it to a group.


 


This is what I have tried and failed:


·         I have left the smart object to determine the destination user, and the destination type was left at user, this randomly chose one user out of my result set.


·         I have left the smart object to determine the destination user, and the destination type was changed to Role and group respectively, this broke the flow.


·         I have created a role that calls the smart object, but it cannot accept input parameters at run time.


 


Your assistance would be greatly appreciated!


 


Regards


 


 


12 replies

Userlevel 4
Badge +14

If I understand correctly you are trying to Redirect/Delegate to a Group or Role, if so this is currently not possible. L


HTH


Vernon

Badge +2

This is quite unfortunate, what I will try now is to write custom code in the DestinationRule_ExecuteCode method and hold thumbs I don’t break anything ;)


In K2.net 2003 I did something similar e.g.


 


For Each dr In dt.Row


If dr.Item("username").ToString().Length > 0 Then


K2.Destinations.Add(DestinationType.User, dr.Item("Username").ToString())


End If   


Next


 


But will let you know if it works. Hold thumbs!


 

Badge +10

Sorry you are having to break into code to accomplish. But please do let us know how this progresses and what you come up with.


 


Thanks!

Badge +11

If you have changed the underlying stored proc, refresh your SQL Service instance.  Map the stored proc call to a SmartObject list method instead of a Load method.  Use the SmartObject List in the destination (of type User) and the task will be assigned to all users returned by the SmartObject. 

Badge +2

Youll notice on my screenshot. I have done that, but not matter how big my list of users returend by the stored proc, it always goes to the second person in the list. Wierd...


14285i367C7A0137D5F80A.jpg
Badge +11

Hi


I had this problem before and used the following approach


1. Create a web service that returns the following: Domainuser1,DomainUser2...


2. you can control the parameters passed to the web service from within the k2 process by using the DataFields. thus you can conrol the users returned


3. Add a reference to the web service in the k2 process


4. When you create an activity in the process use the default wizard and make sure in the destination rule to have only the follwoing value "ProcessOriginatorName"


5. In All the destination rules of Activities use the following code to call the web service and assign the users to that specific activity - you should first open the view code of the destination rule-


 private void DestinationRule_ExecuteCode(object sender, EventArgs e) if  (K2.ActivityInstance.SlotInstance)


 


 



 


 



 


//



 



 


// The activity is a slot instance activity



 



 


//



 



 


int slotCount = 0;  


string[] slotInstanceData = null;

 


if(K2.Configuration.DynamicSlots)  


 


{


// If it is dynamic slot, get the slot count from



 



 


// the initialization data



slotCount = K2.Configuration.SlotInstanceData.Length;


slotInstanceData = K2.Configuration.SlotInstanceData;


}



 



 


else



{


 


// Get the slot count and prepare the initialization



 



 


// data



slotCount = K2.Configuration.Slots;



slotInstanceData = 



 


new string[slotCount];

 


string initData = string.Empty;

 


if(K2.Configuration.SlotInstanceData.Length > 0) for (inti = 0; i < slotCount; i++)


 


 


{


initData = K2.Configuration.SlotInstanceData[0];


}



 



 



{


slotInstanceData = initData;


}


}



 



 



// Set the slot count and initialization data



K2.Slots = slotCount;


K2.SlotInstanceData = K2.Configuration.SlotInstanceData;


}



 



 


else



{


K2.DynamicQueues = K2.Configuration.DynamicQueues;


K2.ResolveQueuesToUsers = K2.Configuration.ResolveQueuesToUsers;



 



 


int setCount = K2.Configuration.SetCount;

 


using (UserManagement.WorkflowSvc oService = new WorkflowSvc()) // my web service is called usermanagement 


 


{


int Parameter1= Convert.ToInt32(K2.ProcessInstance.DataFields["Param1"].Value);  


string Parameter2= K2.ProcessInstance.DataFields["Param2"].Value.ToString();

oService.Url = K2.StringTable[


 


"UserServiceURL"]; // UserServiceURL this is the name i added to the string table "Workflow Server > Processes > MySolution > MyProcess> String Table " , it contains the path to the web service string sUsers = oService.UsersGet(Parameter1, Parameter2);  


 string[] oUsers = sUsers.Split(',');  


foreach (string oUser in oUsers)  


{


if (!string.IsNullOrEmpty(oUser))




K2.Destinations.Add(D



 


estinationType.User, oUser);


 


 

Badge +11

 


 



 



 


foreach (string oUser in

oUsers)

{



 



 


if (!string.IsNullOrEmpty(oUser))



K2.Destinations.Add(



 


DestinationType.User, oUser);



}

}

}




Badge +13

Conceptually, if you return a list of users from a group/role then 1) server event is executed per user, 2) membership change in group/role will not reflect in permission.


You can create conditional code in the destination rule that will assign to role/group and have a line routes back to the same activity when Redirect action is used.

Badge +2

Okay everyone, I’ve finally made a breakthrough.


 


What I have done is the following:


 


Created a SQL stored procedure that returns either one username e.g. ejohnson or several users that is separated by a comma. E.g. ejohnson,jputter,awilsch.


Depending on what you need from your input parameter.


 


Got the Idea from BasharA


 


Then a smart object was created for that proc, for black pearl to use.


On the Activity’s destination users I referenced that smart object. The Options where, “Plan Just once”, “Number of slots to be created” = 1,


Then Ive edited the Destination rule’s code behind, Ive changed the function AddDestinations from:


   // Iterate through the rest of the list and add each


                // destination with its corresponding type.


                for (int i = 1; i < destinations[row].Length; i++)


                {


                        K2.Destinations.Add(destType, destinations[row]);


                }


 


To:


   // Iterate through the rest of the list and add each


                // destination with its corresponding type.


                for (int i = 1; i < destinations[row].Length; i++)


                {


                    if (destinations[row].Contains(","))


                    {


                        string[] sDestUsers = destinations[row].Split(',');


                        foreach (string sUser in sDestUsers)


                        {


                            K2.Destinations.Add(DestinationType.User, sUser);


                        }


                    }


                    else


                    {


                        K2.Destinations.Add(destType, destinations[row]);


                    }


                }


 


And VOILA, it works perfectly!!!


 


Thanks everyone for all the help.

Badge +13

If it's single user doesn't split just returns that 1 item and this will execute fine?


                        string[] sDestUsers = destinations[row].Split(',');


                        foreach (string sUser in sDestUsers)


                        {


                            K2.Destinations.Add(DestinationType.User, sUser);


                        }

Badge +2

It works well for me...

Badge +11

you are most welcomed!


One more thing:


The stored Procedure should ALWAYS bring users. if it dooesnt return users the an error will appear telling you that the activity should at least have one destination user

Reply