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