Skip to main content
I have a process that executes when a user checks out a document from a specified WSS document library. Can the userid of the person checking out the document be resolved in Studio? The first Client Event of the process needs to go to that person -- Destination User.
Hi Tammie,

You can get the name of the person who checked out the document.

What you need to do is the following:

1. When you run the template for the SharePoint process you must select to create the 'Checked Out To' datafield. (This will then automatically get populated K2.net side when the process starts from the 'Check Out' event in SharePoint.)

2. The data returned from SPS might include some weird characters before the actual domain name of the person the document is checked out to. This is default behaviour from SharePoint returning a value that it had to perform a lookup on. In my case the name returned was "1;#K2megaAdministrator". I had to split the string after the "#" and save the value back to the 'Checked Out To' data field.

3. Now that you have the name of the originator in the 'Checked Out To' field you can modify the destination rule of your activity where the user has to be set as destination with the following code (Assuming that you save the user name in 'Checked Out To' data field):

string destRule = K2.ProcessInstance.DataFields["Dest"].Value.ToString();
K2.Destinations.Add(DestinationType.User, destRule.ToString());
Hmmm, the Display Name is captured in the Checked Out To field in our environment so the name doesn't resolve as a valid destination. How can I retrieve the userid? Also, we're working within multiple domains so somehow the domain needs to be resolved also.

BTW, the Checked Out To fied displayed a "read only" error so I created a new data field named AuthorName to capture this data.
The plot thickens...

OK - What i suggest you do is change the column AuthorName to be the same as in the attached image. This will display the domain name of the user which can then be used to set the destination rule.

You can hide the column in the view if you want to.
It's not because I want to make matters more difficult, it's because I must.....

I can see where the =ME function can come in handy in other circumstances but this isn't one of them. It appears =ME doesn't capture the domainusername upon checkout of the document which, from what I can see, is what needs to happen to make this work. The documents we're working with already exist in the library (with AuthorName=Null).
OK - So in this case the AuthorName column will not be populated... Argh!

There is only one way that I can think of... You will have to pass the name in the 'Checked Out To' column to K2.net and query AD to return the SamAccountName for the user.

Here is some code that can return the SamAccountName for a specified name:

DirectorySearcher ds = new DirectorySearcher();

if(name.IndexOf(""") != -1) //Find sAmAccountNam
{
ds.Filter="sAMAccountName= " + name.Substring(name.LastIndexOf(""")+1);
}
else if(name.IndexOf("@") != -1) //Find by email
{
ds.Filter="mail= " + name ;
}
else
{
ds.Filter="sAMAccountName=" + name;;
}

SearchResult sr = ds.FindOne();
if(sr==null)
{
Error = "Please check that the user you trying to add is valid. Please note that only one user can be added";
return;
//throw new Exceptions.UserNotFoundException("User :" + name + " could not be added.");

}


DirectoryEntry de = sr.GetDirectoryEntry();
string samAccount = de.Properties["sAMAccountName"].Value.ToString();


//if the samAccount = de.Properties["sAMAccountName"].Value.ToString(); code throws an exception, use the code below
de.RefreshCache();
ActiveDs.IADsPropertyList propList = (ActiveDs.IADsPropertyList)(de.NativeObject) ;
try
{
ActiveDs.IADsPropertyEntry propEntry = (ActiveDs.IADsPropertyEntry) propList.GetPropertyItem("sAMAccountName", (int)ActiveDs.ADSTYPEENUM.ADSTYPE_DN_STRING) ;
}
catch (Exception ex)
{
string error;
error = ex.Message;
}

Hope this helps! Maybe someone else has other ideas?

Cheers!

Reply