Showing posts with label K2 BlackPearl. Show all posts
Showing posts with label K2 BlackPearl. Show all posts

Wednesday, November 28, 2007

Voyages with BlackPearl - 4. Replace InfoPath Attachments

I am using InfoPath as the user interface to a K2 BlackPearl workflow. The form allows attachments to be added and they will need to be accessible to other users as the workflow progresses. Since the attachments are quite large, I wanted to strip the attachments off and replace them with a link. This workflow allows mutliple attachments and there are several different files that can be attached. The workflow itself makes no refrence to the attachments. I would have used the K2 wizard to store the attachment to a SharePoint document library but it doesn't work for repeating nodes of file attachments and I would need extra code to find the file name and store this in the InfoPath form as a hyperlink, and then delete the original attachment.
My solution was to build a web service that does exactly what I want. Remove the attachment, store it in SharePoint, put the path to the document on another field and repeat this for all occurrences in the repeating node.
The challenge then is to forward the now amended InfoPath form onto the K2 InfoPathService.asmx.
Here is how its done. You'll need a class defined for an XmlNode Array because that is how the InfoPath form is submitted to the InfoPathService.asmx.
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-05-17T16:24:11")] [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-05-17T16:24:11", IsNullable = false)]
public class nodeArray { [System.Xml.Serialization.XmlArray()] [System.Xml.Serialization.XmlAnyElement()] public System.Xml.XmlNode[] node; }

Then the web service method looks like this:
public void InfoPathReplaceAttachment(Object infoPathFormXml) {
nodeArray nodes = new nodeArray();
nodes.node = (System.Xml.XmlNode[]) infoPathFormXml;
string s = System.Web.HttpUtility.HtmlDecode(nodes.node[0].OuterXml);
// load the string into an XML dom called myDoc and replace the attachments
//.....
//Finally submit the XML to the InfoPathService.asmx
// do this to use escaped XML
XmlNode escNode = myDoc.CreateTextNode(myDoc.OuterXml);
// replace node with the amended version
nodes.node[0] = escNode;
infoPathFormXml = nodes.node;
K2submit.InfoPathService ws = new K2submit.InfoPathService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
ws.SubmitInfoPathData(infoPathFormXml);
ws.Dispose();
myDoc = null;

Monday, November 26, 2007

Voyages with BlackPearl - 2. SharePoint permissions

I have a K2 BlackPearl workflow that is integrated to an InfoPath form. The workflow creates a number of InfoPath client events each with a different view.
Users will initiate the workflow from SharePoint, clicking on a link on the home page which opens the initial view of the form. As the workflow advances to the next InfoPath client event it adds a copy of the InfoPath form to the form library that I specified when I attached the form to the workflow.
So I was wondering what are the minimum permissions I need to give users to this site in order for them to create workflows but not edit anything else?
I created a SharePoint group called 'WorkflowUsers' and added my users (or AD groups if you're smart) as members. I gave the group WorkflowUsers 'Read' permission to the site. The lists, libraries and other SharePoint objects inherit this permission. But Read permission is not enough to initiate workflows in this situation. WorkflowUsers also have to have Contribute permissions on the K2 BlackPearl Data Connection library and on the Form library where the workflow stores the forms. This is achieved by navigating to each, change the settings and using the Edit Permissions option to break the inheritance form the site. You can then change permission to Contribute for the WorkflowUser group.
I give the K2 Service account full permission to the site, which is probably more than is necessary but then it's just a service account.

Voyages with BlackPearl - 1. KPRX size

I've create a process in K2 BlackPearl that is quite large. The file size of the KPRX is about 8MB. The trouble is that every time I save it, even if I make no changes, the file size increases - this is with Hotfix 2.01 applied.
I started investigating and found that some redundant nodes are created when a KPRX file is saved. These nodes are used to define the layout of lines and activities but ghost copies are created every time you save.
These nodes are:
/Process/Views/DocumentView/LinesLayoutData/DocumentViewLineLayoutData and
/Process/Views/DocumentView/ActivitiesLayoutData/DocumentViewActivityLayoutData
Each time I save the KPRX I found that it created another copy of the nodes, each has a different Guid but the Name element (amongst others is blank).
This may sound trivial but with some 25 activities and over 50 lines each time I saved the KPRX it would increase the file size by 100KB.
So I wrote a utility that iterates through all these redundant nodes and removes them from the KPRX. I've used it many times and it has no adverse effect on the KPRX file, but the benefit is that it loads quicker and is less likely to give me an out of memory error.
If you want a copy of this KPRX cleaner ping me an email and I'll send it to you. It's a simple .Net Windows application that will prompt for the location of your KPRX file and creates a copy of the cleansed version.