Skip to main content
Hi Everyone,

If you need to implement dynamic resolutions please do as follow

K2.Net Studio

While creating your process in k2 studio , please drag and drop a destination rule i.e. drag and drop user and swtich to generate code.

Look for this in generated code

K2.Destinations.Add(DestinationType.User, "K2MEGAAdministrator")

Replace it with following

K2.Destinations.Add(DestinationType.User, lcase(trim(K2.ProcessInstance.DataFields.Item("Manager").value)))

Please add a process instace data field by right click on k2 workflow editor and add a data field named manager.


Aspx Page

In you aspx page where you need to mention the destination user please do include following ....

' --------------------------------------------------
' To Dynamically Route
myProc.DataFields.Item("Manager").Value = "K2MEGASams"

'------------------------------------------------------------------------
Please include this line in your aspx page where you want to route the process. Ofcourse you can pick values from sql and assign it.

That's all ..have fun
I am trying to set up a dynamic destination using Infopath

my code in the destination goes something like this:

sSchema = K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value

K2.Destinations.Add(DestinationType.User, SourceCode.K2Utilities.XMLFieldMod.GetXMLValue(sSchema,"my:myFields/my:ExpertUser")

The problem is that the ExpertUser field in the infopath form has not yet been filled out. It is only during this activity that it gets assigned.

What can I do? If I set this up in the next activity it will work but it's too late
By the time the Destination Rule is executed, the Activity has got no idea of what Events it contains - let alone the data that needs to be filled out by the user.

Maybe I'm misunderstanding but how can you send the item to 'ExperUser', when 'ExperUser' hasn't decided that he want to send it to 'ExperUser'??

Can not be done.

Please elaborate if I'm misunderstanding,
Ockert
I tried this but got the following errror:

Compiling Work Report(DestRule)...
Compile Error: Work Report(DestRule) Line 13: 'SourceCode.KO.DataFields' does not contain a definition for 'Item'

Here's the full code:

public void Main(ref DestinationRuleContext K2) {


SourceCode.K2Utilities.DSHelper oDSH = new SourceCode.K2Utilities.DSHelper(SourceCode.K2Utilities.DSHelper.DSHelperNewOptionsEnum.DefaultLDAPDomain);
System.DirectoryServices.DirectoryEntry oDEManager;
string sManager;
bool bAllTrue = true;
CDest1 oDest1 = new CDest1();
oDest1.Main(ref K2);
if (oDest1.IsSuccess == true) {
//== sendto
K2.Destinations.Add(DestinationType.User, lcase(trim(K2.ProcessInstance.DataFields.Item("Manager").value)));

if (bAllTrue == false) return;
}
}
Eish... Try using square brackets around "Manager".

Regards,
Ockert
Hi,

Looking at the following line of code that you have:

K2.Destinations.Add(DestinationType.User, lcase(trim(K2.ProcessInstance.DataFields.Item("Manager").value))); 


A number of things are wrong with this code:

1. The Name of the data field must be square brackets [] and not round.
2. No need to have Item , refer to sample below.

.Value.ToString()); 


3. Your string manipulation in this section is also incorrect, Trim cannot be used in the way you use it in this sample + C# is case sensitive
4. lcase does this exist in C#? The sample below is what you are looking for

string MyVariable = MyVariable.ToLower().Trim(); 


Tip: No need to force a string value to Upper or Lower case in a destination rule, K2.net is not case sensitive when working with User.
Thnx guy... It's working now

Reply