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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7Ui6dDhe4qO3AOCMs27VjPgN0626CEpRSROxBu0loQOP8eUCGUw3sd_7KuLLYtbKvBBrnyOoGMeoKFF0OTEqiOvTCks9uRfNuNwRCiREmxJNf9XezcGdtu1wNjl4RZyM8w653xDgsyb8/s400/img+1+-+smart+objects.png)
In the InfoPath SmartObjects integration (from K2 designer) select Create method from Single methods of the SmartObject for the document library.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG9oD3IoYGdcchKOYmNqmRaEk3IX1pU3Q6XgFJ8eu9dHIv0UutSYC6Aquo7T8w05O-R8ZxAKRMkbM3nxln1NRPygOraw-uzhkHerwB4uYnOU1lCKEnPJ218bjWqlnkh5JftcwzInbD9_c/s400/img+2+-+IP+objects.png)
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”.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYYrOT2kHz_udSh8bE59FAmS7EkdRxE8qKd2F0PA7kcIqt_UfVIhYyJXmT8tjLAIXoWMSW4Bgu6hYGatdhIUA-6p1iFuBPBQW_klXUBvHVGu5s1bDMEkN6eOMxGWCW_uUQcc8tbn0RQ_c/s400/img+3+-+rules.png)
Click on value lookup and locate the attachment field from main data source.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpPcwHGmX0CFqeodcy8bs6bcLWr4Cqrsr0C7DLw63q4uvwzHUxn7zBZVG9c_WHeDgxhy_puUGTVKieqAQMA1QzQaucZ8jVljJNnasBTANfLCuIulAVTMyKTpWr5Iz6cVcYOcFD8iRZNbo/s400/img+4+-+rules.png)
Add another action – “Query using a data connection” and select as data connection the Create SmartObject method.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIfscdPk1hwmJtSNpAiFdgBtNJm0dvkdm120WDUk9eKdaCMPbvoD7HIWustG33B4zp8UyLglzJjrlVHYf8ee3fqHj8M3ijoaXG-9Is6PaEgVBzER99n4p-m65ip75xFOA1VQIFF4d6hHA/s400/img+5+-+rules.png)
Add another action – “Set a field’s value” and select AttachmentURL field for location. Open formula for value and create a formula like this:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdmLSGED-D9bc6j8PzhrUltHiOSRG5eg1EAOEGR1W3zNgZdu983aW5DxxVnVLDHMQnciaHN2WKzh-_Dr46Pw7RRTvRiYGLM3T1DMjG74WzIfyOtU2dvZt9vzEuOQiNtX8m2IqQCtdUUd8/s400/img+6+-+rules.png)
Where “LinkToItem_K2_ServiceDefined” is from SmartObject return properties:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNO7gkhfJwgrSct6QoUM9Q7TtrEHv_BJ35VHHa4gqYhUMmVTv7tNeEe6Im-YO4OEUDCRpLn5B9Zwr5BLeWTZpGaOr43zN5SHz5462pqaBRWhHU3isFIu5CoQrVtjDkdy9U_ooOIWmHzOU/s400/img+7+-+rules.png)
Add another action – “Set a field’s value” and select AttachementName field for location and as value select FileLeafRef from SmartObject return properties:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinmNzP2bemYFipW9XMYZ7pcIfOAjIAGf8mjhrh_jnKRgAFIb2zM_48D5joXGqXNeeu8cO8RBcRQ17pOEdSucEph1SE4YzD3eI_DLuth2WRqDpBYkpT3w_cQAdWzNwcUgSYtWkadKc7gog/s400/img+8+-+rules.png)
Add another action – “Set a field’s value” and select Attachment field to empty string (so that the rule is executed just once):
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVY4msiaeS0Sf-07xFnPFX9R4TMdPYdxLNQ6JD6eU_wh-_2JUZ0YgK6_1d_RxxlJkP_MFJGY3E77siIbCk-eg2a8z9j3ZTEWqU3DmkvtAC8IWvKmP-KjKPrnu3kNTRjAGGsy8o9unf78o/s400/img+9+-+rules.png)
Result should look like this:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5GusIXAvLpBsf5a1K7tqFroOApzCxx_MKUm3ZLSDVyHT1X9lT1NHTGrPj6Y2pK7UpgnvDj2FrGi0CARQsLERm_NbkpaRsI5_TGtNU9PSERwjG7KkiufXNAdjfT5meID_axDuvbgouNvQ/s400/img+10+-+rules.png)
Well, lot of actions, but this is how things happen with InfoPath :-)
No comments:
Post a Comment