Skip to main content
Feels like a dumb question here, but for whatever reason I'm just not getting it... I have a smart object that I am creating in an activity (via the smart object's 'Create' event) and I would like to pass this smart object to my InfoPath form to display some of the data within it.  How do I go about tying an existing smart object to an infopath form?  Seems like the only likely solution is to integrate the infopath form with the 'getlist' method but then I'm not sure how to get to the specific smart object I had just created.  Please tell me I am missing something simple (wouldn't be the first time)

On your development machine, with infopath and VS installed on it. Right click on the infopath form, and select integrate with SmartObjects. 


 Actually I know a GREAT Video availiable on this subject.  Located HERE


I am sure it will help you. If you need more help let us know.


That is one way of going about it.  So you have an activity, you add the smartobject event to create a smartobject.  Then you have a infopath client event.  You want to load up the smartobject into the form right?  Chris points out a good way of doing it.  One thing, DO NOT FORGET to pass in the id of the smart object into the XML of the infopath form so that when it loads it can use that key. 


So how do you get that new key value into the xml so it will be there when the infopath form opens?  Simple.  Create an activity level field.  Back on the smartobject client event where you call the create method, on the return value to the activity level field you created.  Then add a server side code event between your smartobject event and the infopath client event.  In the code event write code that will take the value and set it into the XML of the infopath form.  Read this thread on how to do this - http://k2underground.com/forums/thread/20831.aspx


Hope this helps - Jason


PS -- HEY CHRIS - I see you are number two on the points ladder - SHAMELESS!!!


Thanks guys, between the two of you I think I am almost there... I have watched your videos, Chris, seconds after you release them but it didn't totally answer my question.  Japergis seems to know where I am going, but I don't understand where he says 'Back on the smartobject client event where you call the create method, on the return value to the activity level field you created'... I'm assuming he means the part of the wizard where you assign the outcome of the event to a value, but a 'Create' smart object event cannot have an outcome (as far as I can tell, anyway).  Can you please elaborate on this?  I'm at the point now where my form loads all smart objects and displays the first one, but I need to move it to the one I just created.  I suppose I could assume the last smart object is the one I want, is that a good way to do it?  If so, how?


Oh, and Chris is number two on the points ladder only because he posts answers to his own questions... a technique I'm using to climb the ranks myself!  (I kid, I kid, Chris rules) 


 


Are you using SmartBox SmartObjects or are you writing SmartObjects for custom SmartServices that you write?


Check out the screen shots below.  On a SmartObject create an ID will be returned.  In the second screen shot I map a return value from the SmartBox SmartObject into a Activity Level field.  As stated earlier, you can then take that value from the activity level field and set it into the XML of the InfoPath form. 


Note in K2 2003 there was an event to do this value setting but it is not in BlackPearl yet (refer to the post I listed above).  Although personally I did find that event limiting and that you will be better off learning how to write the server side event code to set values.


Jason


original.aspx


 


original.aspx


Ah, I think I see what happened.  I had initially set up my smart object to use 'ClientId' (a text field) as its 'key' column.  When defining a key this way, it apparently does not make it a return value from the 'Create' method.  I instead added a new 'Id' autonumber field and used that as the key, like how you have it defined for your smartobject, and then the Create method returned that value.  Thanks, Jason!

Yeah - that would do it alright.


I needed to respond to get my points up :-)  Watch out Chris.


You wouldn't need the getlist method, you need the load method. Assuming it's a simple Smart Object and you are still using the standard load method, here's what you can do:

  1. Add a data field in your InfoPath form to store the ID of the smart object you're wanting to load
  2. In the INfoPath integration wizard hook up the load event (this will create a data source in your infopath form which you can then query)
  3. In your K2 process after you've created your Smart Object you need to write some code to populate the InfoPath form's ID field you created above (it's all XML - nothing complicated)
  4. now in your InfoPath for you need to create 2 rules in the form load event (tools -> form options). The first rule is to copy the value of the ID from your ID field from step 1 above into the load data source. The second is to query the load data source.
After this you will have your smart object in your infopath form.

I'll write up a quick tutorial with this in more details some time...

Thanks for further explaining some of the things I was leaving out.


If you want to save the data in the infopath form back to the smartobject on submit, all you need to do is hook in the save method in the same way and add a rule to the submit options under tools.


I have a question about that method of saving actually - the only way I could get it to work was to copy the changed fields from the load data source to the save data source in the submit rules. This can be painful if you have more than just a few data fields - is there a better way?

T.

Man - we are on the same wave length here.  I was preparing for some client training and ran into this same problem last night.  I had ten fields and the mapping became a pain for create and save methods. 


Here is the kicker, this pattern only really works with non-repeating data.  Using infopath to call an save method for a repeating set of data is not easy.  I suspect that we will have to either start writing .Net managed code into our forms (which I my opinion I try to avoid).  Keeping InfoPath dump is the best thing you can do - working with it the past few years I have learned do not do too much custom coding in InfoPath.  I am not saying do not use .Net managed code; just understand its boundaries.


Another options would be to write a custom web service that you send your XML to, the web service will shred the XML and then call the same web services the IP form would have called or make direct smartobject API calls to save the data.  At least with code, it is re-useable and you do not have to do lots and lots of clicking.


I have to run but I will do some more brainstorming on this today as I need to figure out what is the best pattern that requires the least amount of effort.


Jason


That agrees with what I've found as well. Like you I avoid adding code to InfoPath forms because deployment becomes a PITA. When I was giving training I very cleverly only persisted one of the fields... saved me about 20 minutes of clicking.

I think your web service idea is a good one if you're saving a lot. I'll have a think about that...

Thanks!

You know it has slipped my mind but you can drag and drop the secondary data source fields for the smartobject web services onto the form.  Then you would not have to move all the values into the main data source.  The assumption would be that when the form is submitted, all the data is saved.  In the K2 process you use the SmartObject event to get all the data into process or activity fields and then use them on line rules.  Problem is you will lose some free stuff you get with Action integration with InfoPath.  So I am 50/50 on doing that right now.


That's true, although you would have 2 secondary data sources, one each for load and save. You cab drag the load data source on and have the smart object's current values displayed (but not saved) or you can drag the save data source on and have the entered values saved but the original values wouldn't be displayed.

Depends on whether or not you're using the fields to add new data or to edit, I suppose.

Reply