Docstoc

How to upload InfoPath File Attachments with SmartObjects v1.0

Document Sample
How to upload InfoPath File Attachments with SmartObjects v1.0 Powered By Docstoc
					Using SmartObjects in InfoPath forms to
 Upload File Attachments to SharePoint
BY JOHNNY FANG | SOLUTIONS MANAGER | K2 APAC



November 2009




This document is intended to demonstrate how we can utilize SmartObject technology to efficiently upload file
attachments in an InfoPath form with no code.
USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




CONTENTS

CONTENTS ......................................................................................................................................................... 2

INTRODUCTION ................................................................................................................................................. 3

GUIDE: BUILDING THE SOLUTION................................................................................................................... 4
     Creating up the SharePoint document list .................................................................................................... 4




                                                                                                                                                              PAGE 2
USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




INTRODUCTION
Using file attachments in InfoPath documents is generally not desirable as a K2 best practice. This can easily
cause significant growth in the K2ServerLog database. Take the following example:

e.g. 2000 form instances. Each form has on average roughly 200KB attachments per form. The process had
a couple of approval stages and has about 2-3 slots per stage. Let's assume a figure of 7 slots here.
Including the process instance data, this would result in 8 copies of the form data.

Also note the following:

       The InfoPath client event makes a copy of the InfoPath document per slot
       InfoPath file attachments need to be base64 encoded. This roughly multiplies the attachment size by
        1.37 times.

This leads to 2000 X 200KB X 1.37 X 8 = 4.18GB of data.

This is a significant size to manage for just 2000 instances. This also multiplies as the process gets more
complex and the number of instances grows over time.

This document is intended to show step by step how we can leverage on K2 SmartObject technology and
SharePoint to store the file attachments externally of the InfoPath document with no code at all.




                                                                                                              PAGE 3
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




     GUIDE: BUILDING THE SOLUTION

     CREATING UP THE SHAREPOINT DOCUMENT LIST
     I’ll first create up a new document library to store my file attachments. I’ll be using my HR site for this
     purpose.

1.      Under All Site Content, click
        Create.




2.      Next select the relevant list type
        that you are working with. I am
        using the default Document
        Library in this example.




                                                                                                                   PAGE 4
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




3.     In this case, I am creating a new
       document library called File
       Attachments and specifying
       Microsoft Office Word document
       for the Document Template.




4.     Click Create and wait for the
       document library to be created.




                                                                                     PAGE 5
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




     CREATE THE FILE ATTACHMENT SMARTOBJECT
     I’ll first create up a new document library to store my file attachments. I’ll be using my HR site for this
     purpose.

1.      First refresh the service definition
        for the SharePoint site. This can
        be done from the Site Actions
        menu if you have turned on this
        K2 feature.




2.      You could create a new
        SmartObject manually via the K2
        designer but in this case I am
        going to use the SmartObject
        Tester tool to do this quickly.




                                                                                                                   PAGE 6
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




3.     Browse to the MOSS instance
       that you have configured. In this
       case, I have registered a
       SharePoint service instance for
       the HR site. Right click on the
       Document Library that you
       created and select Create Smart
       Object.




4.     Click Publish SmartObject and
       you should see a success
       message. This will indicate that
       the SmartObject got created.




                                                                                     PAGE 7
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




5.     Once this is done, you should
       see a new SmartObject under the
       Default folder. At this point, we
       are ready to move on to create
       the InfoPath form and link it to the
       SmartObject.




                                                                                     PAGE 8
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




     CREATE INFOPATH FORM
     I’ll first create up a new document library to store my file attachments. I’ll be using my HR site for this
     purpose.

1.      Let’s create up blank form
        template.




2.      Now I am going to create up a
        couple of fields that I need in my
        main data source. Click on Data
        Source on the side pane.




                                                                                                                   PAGE 9
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




3.     First create the repeating node
       for the file attachment. Right
       click on the myFields node and
       select Add Field or Group.
       Create the repeating node as
       shown on the right. I am calling it
       fileAttachment.




4.     Next add a file attachment field. I
       am calling mine file.




                                                                                     PAGE 10
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




5.     Next add a field for the URL link
       to the document after we upload
       it to SharePoint. I am calling this
       urllink.




6.     The last field we add is used as a
       trigger field to fire the
       SmartObject call for each line
       item when we submit the form.
       I’ll call this field trigger and set
       an initial value of 0 to it.




7.     At this point, the data source
       pane should look something like
       this.




                                                                                     PAGE 11
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




8.     I am then going to drag the file
       field to the form as a repeating
       file attachment control. I’ll also
       add a button control to do the
       form submission.




9.     I’ll drag the urllink to the bottom
       of the form as a repeating
       expression. This will be used to
       show how the URLs are created
       after the submission. Now note
       that in a real life case, the URL
       listing would be on the approval
       view.




10.    Now let’s add the SmartObject
       integration to the form. First save
       and close the form. Then right
       click on the form and select
       Integrate with SmartObject.




                                                                                     PAGE 12
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




11.   Now add in the Create method
      for the SmartObject we created
      earlier.




12.   Leave it as a secondary data
      source. Click OK.




                                                                                  PAGE 13
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




13.   Click Finish to complete the
      SmartObject integration.


      Now note that I did direct SO
      Integration here to the form. In
      the event that we are using
      InfoPath workflow integration, I
      would recommend doing the SO
      integration from the InfoPath
      process wizard itself.




14.   Now right click on the template
      file and select Design.


      First change the Submit button
      rules to set the trigger field to 1
      when clicked on. This is one part
      of the trick to cause the rule
      processing to fire for each row.


      Go to Button Properties.




                                                                                  PAGE 14
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




15.   Under Rules, configure an action
      to set the trigger field to 1.




                                                                                  PAGE 15
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




16.   Next let’s set a rule under the
      trigger field properties.




                                                                                  PAGE 16
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




17.   Click the Add button to add a
      rule.




18.   Under the condition, configure
      the rule to only fire when trigger
      is equal to 1 and the urllink is still
      blank. This is the other part of
      the trick which works in
      combination with the other rule
      that we created on the Submit
      button. So when we click on the
      Submit button, this rule will fire
      for every single line item in this
      repeating group.




                                                                                  PAGE 17
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




19.   Next configure the first action in
      the rule to copy the file
      attachment data to the input field
      of the SO create method data
      source. The field is called
      content.




20.   The final setting should look like
      this. Click OK.




                                                                                  PAGE 18
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




21.   Next add an action to execute the
      SmartObject create function.




22.   Next add an action to set the
      urllink field to contain the
      returned URL link. Note that we
      will use the following Formula to
      strip off the surrounding HTML
      tags that won’t be used.


      substring-before(substring-
      after(LinkToItem_K2_ServiceDefi
      ned, "<hyperlink><link>"),
      "</link>")




23.   This is the formula that we use in
      the Value field.




                                                                                  PAGE 19
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




24.   This is where we select the
      LinkToItem_K2_ServiceDefined
      field which has the returned URL
      link. After this is all configured,
      complete adding the action by
      clicking OK.




25.   Next add an action to remove the
      file data from the InfoPath form.
      Set the file field to an empty
      value. This is important as the
      file data will still be in the
      InfoPath form if you do not do
      this.




                                                                                  PAGE 20
  USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




26.   You rule dialog should now look
      like this. Let’s the save the form
      and test it out now.




                                                                                  PAGE 21
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




     TESTING THE FORM
     Now we have completed setting up the basic functionality of how we can upload multiple documents in the
     InfoPath form to SharePoint using SmartObjects. Let’s test it out.

1.      I first open up my form and I then
        attach 2 text files for testing.




                                                                                                           PAGE 22
     USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




2.     Click Submit. Note the first time
       executing this might be a bit
       slower when the SmartObject
       web service is being called the
       first time (it should be quicker on
       the subsequent calls).


       Now notice how the two
       attachment files are removed and
       note the URL links listed under
       the Submit button.




3.     Now if you look at the document
       library that created earlier. We
       can now see the 2 file
       attachments that uploaded via
       the form. Cool!




                                                                                     PAGE 23
USING SMARTOBJECTS IN INFOPATH FORMS TO UPLOAD FILE ATTACHMENTS TO SHAREPOINT




FINAL THOUGHTS
Now this has been a pretty short demo on how we can utilize SmartObjects, InfoPath and SharePoint to
provide a relatively easy way to abstract out file attachments from InfoPath forms.

There are other areas that were not covered here (as we wanted to focus on this specific functionality and not
a full fledge application).

    1) Handling duplicate file names
    2) Workflow Integration
    3) Nicer looking form user interface with multiple views for the approver and submitter.

I hope you will find this article as a useful reference. Cheers.




                                                                                                          PAGE 24

				
DOCUMENT INFO
Shared By:
Tags:
Stats:
views:15
posted:10/5/2012
language:
pages:24