Dynamic Destinations


Badge +1
I have an existing application that my client wants me to workflow enable. They are storing their users/ groups in their own SQL database. Is is possible to write code in the destination rules to call a custom web service that grabs all the destination users from the SQL database and assign them to the desination on the fly?

10 replies

Badge +11
Sure you can retrieve and assign the users to Destination Rules on the fly. The question is - where/what will K2.net Server authenticate the users against when they try to open their worklist items? Will the users be authenticated against AD?

If this database is the only place usernames and passwords are being maintained and K2.net Server needs to authenticate users against this database, you will need to write a custom user manager utilizing this database. I would recommend to download our SQL User Manager component (the very first version 3.4201.1.0) which contains the source code to the component to use as an example.

Regards,
Ockert
Badge +1
All our users are in AD

Its just that the developers in our organization do not have access to be able to create AD groups and assign users to groups

Our clients want to be able to assign users to destination groups through the use of an aspx / sql server Administration tool

The idea is that our users will use our aspx admin tool to assign users to destination groups which will be saved in our SQL database, then in K2 I will write some custom code that accesses a web service that will return all the destination users from the database for the particular activity.

For this scenario do you think that I will still have to create my SQL user manager component to authorize users who try to open their worklist items?

I am planning on writing a custom K2 web service which my admin tool will invoke to update the process instances AND use smartmenus which can do the same thing if users want to use Sharepoint to approve documents

I hope I'm not crazy in thinking that this is all possible
Badge +9
If you are storing fully qualified Active Directory names (DomainNameUserName) in the external SQL tables (maintained by your ASP.NET admin tool) you should not need to implement a custom User Manager.

However, you will need to write some custom code within the K2 process that interacts with your proposed webservice to retrieve a list of destination users (fully qualified AD user names) and then manually assign these user names within the Activity's Destination Rule.
Badge +5
I'm trying to do something similar - is it possible instead of using SQL Server DB to store these DomainnameUsernames in an XML file? If so, can someone point me to some docs that can give me step by step instructions on how to do this?
Badge +9
That should certainly be possible. Unfortunately I don't have any step-by-step example.

At a high level, you'll need to :

1. Create the XML file, in whatever structure you'd like
2. Locate the XML file in a location that the K2 Server Service account can reach (perhaps the K2 server itself)
3. Edit the code of the Activity Destination Rule. In here, you'll use the regular Microsoft .NET framework XML classes to open the file and retrieve the users then add them to the destination rule programatically.
Badge +5
Thanks Bob! I suppose I'm not as familar with the XML feature and where to begin. How would K2 know the structure that I'm going to set up? Do you have any links or resources that could possibly have some more details?
Badge +9
Just to be clear, this will require you to write .NET code within the Destination Rule for the Activity(s) in K2.net Studio. As such, since you will be creating the XML file and you will presumably also be writing the .NET code in the K2 Destination Rule, you should have the knowledge of the XML schema to program against using the .NET XML classes.

Below is a C# code snippet that shows how to pull the user values from a database table within Destination Rule code. You'll need to replace the the database specific calls with .NET XML class calls (sorry I don't have any such examples). They key thing to do is loop through the XML nodes and call "K2.Destinations.Add(DestinationType.User, <<user name from xml>>);" for each user.

As for how to code against the .NET XML objects (i.e. XmlDocument), there are numerous resources and tutorials on the internet. Searching for something like "how to use XML in .net" should reveal quite a bit of information for you to use. This will be pretty much straight .NET coding, with the only real K2 specific piece being the call to the K2.Destinations.Add() mentioned above.

.ToString();
// add the user to the K2 Destintion
K2.Destinations.Add(DestinationType.User, strUserName);
}
// close the reader
dbRdr.Close();
// discard the command
dbCmd.Dispose();
}
catch (Exception ex)
{
throw(ex);
}

}

}
Badge +5
Thanks for the help Bob! That helps a lot.
Badge +5
Bob,

I just tried your code sniplet using a SQL Query and as I'm debugging this I'm getting this error - "EXECUTE permission denied on object sp_sdidebug, database master, owner dbo" Some one recommended disabling SQL Server debugging and looking at the startup properties of VS2005 it looks to be already disabled.

I then ran this code outside of K2 in a VS Web page (took out the K2 References) and it works. Any ideas?

Thanks,
Vinny
Badge +9
Does the K2 Server service account differ from the credentials that ASP.NET page runs under? If so, I'd compare the two accounts' permissions in SQL, specifically within the Master DB.

Reply