Friday, May 29, 2009

K2 Blackpearl: Useful posts to configure ditribuited environment

This week I have been involved in the K2 Blackpearl environment setup. When you install it on a single machine the setup is very easy and fluent thanks to the installer provided by SourceCode. The activity began more difficult when you have to install various components on different machine in a distributed environment. In fact to allow multiple components communication it's required Kerberos Delegation. Here I posts some very handy reference to accomplish this tricky activity:
kick it on DotNetKicks.com
Save to delicious 0 saves

Wednesday, May 13, 2009

K2 Blackpearl: Set Sharepoint Task List Item Permission by code

Again on Sharepoint Workflow Integration Process... In the same process used in this post, I had to set particultar permissions to two custom sharepoint groups on the Tasks item created in Sharepoint Workflow Integration Client [SWIC]. In particular my goal was to set "View Only" permission to the following groups:
  • Approvator Box Push
  • Collaborator Box Push

where Box Push is my Sharepoint List with my K2 integrated workflow. Because I want to set this permissions when the task item is generated, in this case I cannot use "Sharepoint User Management" [SUM] event because I have the task item ID only when the item is created (see again this post). If you think to use SUM after the SWIC event, you haven't the desired behavior because process instance waits a user action to go on and permissions are set too late. So, to achieve my purpose I needed to write custom code in SWIC event after I get task item ID. In "ExecuteForUser" method body I call a K2 sharepoint web service (installed by K2 on MOSS) used to set permission on generic item (site, list or item list) hosted on MOSS solution. The code to call this service is the follow:

SourceCode.SharePoint.WebServices.K2SPPermissions K2SPPermissionsPRx =
  new SourceCode.SharePoint.WebServices.K2SPPermissions();
K2SPPermissionsPRx.Url = new K2Uri(MyUrl).FormatURI(true) +
     "_vti_bin/K2SPPermissions.ASMX";

ADCredentials directoryCredential = new ADCredentials();

K2SPPermissionsPRx.Credentials =
  directoryCredential.GetCredentials(K2SPPermissionsPRx.Url);

K2SPPermissionsPRx.SetSiteWidePermissionsFromXml(XML_FOR_PERMISSION);
where MyUrl is the Sharepoint site url. This service gets in input a xml string describing the permissions to assign. An example could be this:
<Group>
  <Filter> YOUR MOSS SITE </Filter>
  <SharePointPeopleAndGroupsItem>
    <Url>
      <SharePointSite> YOUR MOSS SITE </SharePointSite>
      <SharePointList>Tasks</SharePointList>
      <SharePointFolder></SharePointFolder>
      <SharePointListItem> YOUR ITEM ID </SharePointListItem>
      <SharePointGroup></SharePointGroup>
    </Url>
    <SharePointItemType>SHAREPOINTLISTITEM</SharePointItemType>
    <UserOrGroupCollection>
      <UserOrGroup>
        <LoginName>Approvers Box Push</LoginName>
        <Type>Group</Type>
      </UserOrGroup>
    </UserOrGroupCollection>
    <K2SharePointItemCollection></K2SharePointItemCollection>
    <K2UserOrGroupCollection></K2UserOrGroupCollection>
    <BreakRoleInheritance>True</BreakRoleInheritance>
    <CopyRoleAssignments>False</CopyRoleAssignments>
    <RevokeDefinitions>False</RevokeDefinitions>
    <AssignSiteMemberPermission>False</AssignSiteMemberPermission>
    <SharePointPermissionCollection>
      <SharePointPermission>
        <Name>Full Control</Name>
        <Type>REVOKE</Type>
      </SharePointPermission>
      <SharePointPermission>
        <Name>Design</Name>
        <Type>REVOKE</Type>
      </SharePointPermission>
      <SharePointPermission>
        <Name>Manage Hierarchy</Name>
        <Type>REVOKE</Type>
      </SharePointPermission>
      <SharePointPermission>
        <Name>Approve</Name>
        <Type>REVOKE</Type>
      </SharePointPermission>
      <SharePointPermission>
        <Name>Contribute</Name>
        <Type>REVOKE</Type>
      </SharePointPermission>
      <SharePointPermission>
        <Name>Read</Name>
        <Type>REVOKE</Type>
      </SharePointPermission>
<SharePointPermission>
 <Name>Restricted Read</Name>
<Type>REVOKE</Type>
</SharePointPermission>
<SharePointPermission>
<Name>View Only</Name>
<Type>ASSIGN</Type>
</SharePointPermission>
</SharePointPermissionCollection>
</SharePointPeopleAndGroupsItem>
</Group>
in my particular case I set "View Only" to "Approvers Box Push" group but you can set your desire permissions substituting ASSIGN to REVOKE label. In this way I achieve my purpose, in fact when a user member of Approvers Box Push open a task Item he or she could only view it (see the picture below). These permissions are set only to the item; on the Tasks list, users can add new task item as they want (as showed in the follow picture):
kick it on DotNetKicks.com
Save to delicious 0 saves

K2 Blackpearl - Get Task List Item in Sharepoint Workflow Integration

Using K2 Blackpearl features like Sharepoint events can be very usefull and easy to develop a workflow in few minutes. Althought, sometimes there are pitfalls that frustrate your initial purpose. For example, one of this day, I run against Sharepoint Workflow Integration features. I create my simple approval process in figure but, initially, I can't to get the task item ID created during Sharepoint Workflow Integration Client [SWIC]. I needed this ID because in my final activity I set a Sharepoint List Items event to delete the Task List Item created during the previous activity (SWIC, see Delete Task Activity in the figure above). To accomplish to this necessity, I had to create a new process DataField which I called "TaskId" Then I had to go inside the code generated by SWIC event and I modified the ExecuteForUser method body in the follow manner:
string taskIDstring = service.ModifyWorkflowAndGetTaskID(listId, listItemId,

                          workflowInstanceId, modificationID, contextData, "");



// Put task item id into process data field "TaskID"

string taskID = taskIDstring.Split(new string[] { "?ID=" },

                        StringSplitOptions.None)[1];

K2.ProcessInstance.DataFields["TaskID"].Value = taskID;
"service.ModifyWorkflowAndGetTaskID" calls a K2 web service who return a string contain the url of the task. A string like this: http://your MOSS server/Lists/Tasks/DispForm.aspx?ID=3.
Thank to this code I'm been able to delete Task List Item at the end of my process:
kick it on DotNetKicks.com
Save to delicious 0 saves