Saturday, 13 August 2011

Save InfoPath Attachment via K2 SmartObject

If you have met K2 during your work, you will know how important is to keep K2 DB clean and less-busy in order to improve performance in workflow execution, reporting etc. One of the ways to improve the performance is removing all attachments from InfoPath forms before they reach to K2 DB, because InfoPath data will be extracted, saved and passed back to the customer by K2. Here is how this can be done (note that I am talking for K2 [blackpoint], but more or less the same procedure can be used for K2 [blackpearl] as well).


Attachment can be saved to a SharePoint document library on Submit form event, before “post form data to K2” is called. As a result, we will get file location and later on can use this location to provide access to the file. K2 SmartObjects should be enabled for the destination document library.

In the InfoPath SmartObjects integration (from K2 designer) select Create method from Single methods of the SmartObject for the document library.

Create 2 text fields in InfoPath data source: AttachmentURL and AttachmentName (these will keep file location so that we can configure a nice-looking link on View form).
Open InfoPath form submit rules add a rule “Upload File” with condition that attachment field is not blank.
For “Upload File” rule add an action, select “Set a field’s value”. Open Field lookup, select the SmartObject as data source, expand query fields and select “content”.

Click on value lookup and locate the attachment field from main data source.

Add another action – “Query using a data connection” and select as data connection the Create SmartObject method.

Add another action – “Set a field’s value” and select AttachmentURL field for location. Open formula for value and create a formula like this:

Where “LinkToItem_K2_ServiceDefined” is from SmartObject return properties:

Add another action – “Set a field’s value” and select AttachementName field for location and as value select FileLeafRef from SmartObject return properties:

Add another action – “Set a field’s value” and select Attachment field to empty string (so that the rule is executed just once):

Result should look like this:

Well, lot of actions, but this is how things happen with InfoPath :-)

No comments:

Post a Comment