Modifying the contents of a SmartObject using the SmartObject event, and then loading the SmartObject into InfoPath

This blog post is really a little tutorial that I’ve been working on to help people understand how to utilise SmartObjects as part of their InfoPath forms. I, like many, just think it’s more logical to store data in the SQL database (SmartBox) rather than to store it as XML (in the InfoPath form itself. This tutorial should help you get an idea of how to use SmartObjects to persist your data, while keeping the familiar InfoPath front end for your users.

First you need to create your SmartObjects using the Visual Studio SmartObject project. This tutorial wont cover that as it’s covered in the K2 [blackpearl] 101 guides. Make sure that when you do create them that you give them a Load and Save method in order to follow what I’ve done here.

tutorial1
Figure 1: K2 [blackpearl] SmartObject Event wizard

Figure 1 shows a SmartObject event wizard. I am using this wizard to set some values of the SmartObject. I will be calling the ‘Save’ method of my SmartObject ‘cmmiDocumentDetail’.

tutorial2
Figure 2: K2 [blackpearl] SmartObject Event wizard (2) 

Figure 2 shows the values of my SmartObject that I will be populating outside of InfoPath. I’m populating ‘currentAuthor’ with the Activity Instance Destination User (how to get this particular value is explained on this blog too :-)) and current role with a string "Review" and the ‘documentAutoNumber’ with a value from a previous InfoPath form. Populating this field is a key requirement, as this is the index of my SmartObject. If you do this sort of thing you will need to populate this value to make sure you are updating the correct instance of your SmartObject.

tutorial3
Figure 3: K2 [blackpearl] InfoPath Integration wizard

If you haven’t already done so, integrate your SmartObjects with your InfoPath form using the edit mode provided by the InfoPath integration mode. You may encounter issues if you’ve added your own datasources before integrating your SmartObjects. See K2 Underground. After you’ve integrated each of the SmartObject methods that you want to use (Yes, you need to integrate each method separately!) you can carry on with this tutorial.

Figure 3 shows the ‘design’ mode that you will need to enter in order to make any changes to an InfoPath form that is already integrated with your workflow. You really shouldn’t modify the InfoPath form outside of Visual Studio once you’ve integrated… it’s just not worth the risk ;-).

tutorial4
Figure 4: InfoPath form options selection

Figure 4 shows the form options mode that we’ll need to go into in order to invoke the SmartObject methods that we will require.

tutorial5
Figure 5: InfoPath open and save rules selection

Figure 5 shows the open and save rules that we need to get to to invoke the SmartObject methods on form load event.

tutorial6
Figure 6: InfoPath open and save rules

You’ll now need to add an action to invoke the load method of your SmartObject. If you require to load multiple SmartObjects you’ll need to add actions for each one separately. Figure 6 shows two Queries, one a ‘Get List’ and one a Load method on two separate SmartObjects. If you invoke a SmartObject method that has an input parameter, you’ll need to add another action that sets a field value on the relevant data source (See Figure 7 below)

tutorial7
Figure 7: InfoPath data source window showing the load method and it’s required input 

Figure 7 shows a required input parameter to the load method. This is the field that you will need to set before you query the SmartObject. If you look at Figure 6, you’ll see that I set ‘docAutoNumber’ to be equal to a value before I invoke the Query. This is important as the SmartObject method will error if no input parameter is provided.

Now that you know that when the form opens you will be automatically executing the SmartObject methods you can set about assigning your SmartObjects to controls on your InfoPath form.

tutorial8
Figure 8: InfoPath data source window showing the return values for the load method 

Figure 8 shows the set of values that can be bound to existing InfoPath controls or dragged and dropped onto your InfoPath form to automatically create controls. Once controls are bound or created you need to ensure you call the ‘Save’ method on your SmartObjects.

tutorial9
Figure 9: InfoPath submit rule options

Figure 9 shows a rule that is executed on form submit that calls the Save method on my SmartObjects. ‘Set Workflow Task Action 1′ and ‘Submit Workflow’ are automatically added by K2 [blackpearl] when you have performed a K2 [blackpearl] InfoPath integration wizard.

I know this is sparse in places… but I hope it helps some of you.

SpittingCAML




You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply