Transferring Context Between Infopath Form

  • 9 February 2008
  • 9 replies
  • 10 views

Badge +2

For simplicity of form configuration, I want to write separate forms for each view (rather than multiple views in a form).  Here's an example of what I'm trying to achieve:


1. User creates a "payment request" via a smartobject using Infopath Form1.  This should create a wok item and start a workflow.


2. Another user gets notified and opens the item.  That would open another form (which lives in another form library) called "approve payment request".


 The problem is...how does the second form have the context (the key that I need) to pull in the data via my smartobjects?    I feel like in the documentation it gives a hint that it's through smartObject events or associations, and I saw a trainer do something with XML fields in the Visual Studio designer, but I've not been able to put the pieces together, so I need a step-by-step.  (this is my first project with Blackpearl and unfortunately it's due Monday.  Help, please!


-alex


9 replies

Badge +7

 


Hi Alex,


Having done something very similar to yourself I think I can lend a hand.



  1. Design your smartobject so that it contains a primary key autonumber
  2. Create the Load, and Save methods for your smartobject
  3. On your first form, when you save your data from your InfoPath controls to your smartobject, use the submit rules to store the returned autonumber as a hidden field on your InfoPath form
  4. Using the _K2 data source added when you use the infopath integration wizard, you can also store the ProcessID and ActivityID in your smartobject
  5. In your workflow, you now know you can get the autonumber (from form XML), ProcessID and ActivityID from the _K2 datasource on form 2
  6. I usually archive the form (to a SharePoint library), and set some form metadata to contain the autonumber also
  7. In your second form, retrieve the autonumber from your smartobject using the processID as a lookup and Load the smartobject data onto your form so the user can approve the data

I hope this kinda makes sense.


Martin

Badge +2

Martin,


 Thanks for your reply, but when I open the Infopath form (in integration wizard) and look at the _K2 data source, I don't see a Process ID or ActivityID.  How do I get them to show up?


 Thanks,


-alex

Badge +7

Alex, my apologies, i've just looked myself and they aren't there... !


I'll check what I did when I get back to work on Monday, however I suspect I did the following:


 


smartObjectID = <whatever value you need from either K2 or previous forms> 


// we need to get the xml from the K2 state data for my form2
// Note: 'form2Name' is the name of my infopath form as it appears in the K2 Object Browser
string k2xmlString = K2.ProcessInstance.XmlFields["form2Name"].Value.ToString();

// get stuff from form2
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(k2xmlString);

// create a namespace manager for InfoPath
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsMgr.AddNamespace("my", xmlDoc.DocumentElement.GetNamespaceOfPrefix("my"));

// set the value of a hidden field to be equal to the id required for retrieving the correct smartobject
// NOTE: I've got a hidden text box on my infopath form calledn 'hiddenSmartObjectID'
// that i'll be using later
xmlDoc.SelectSingleNode("//my:Form2Fields/my:hiddenSmartObjectID", nsMgr).Value = smartObjectID;

//Now set the value back into the XML Field
K2.ProcessInstance.XmlFields["form2Name"].Value = xmlDoc.OuterXml;


 in form2 you can now use the hidden field to gain access to the correct smartobject.


I'm not sure if you'll hit any issues if the form has not been opened before you do all this coding, but the coding is a simple server event code.


 have a go and see what you find out... i'm pretty new at this too.


Martin


 


P.S. thanks to http://k2distillery.blogspot.com/ (japergis) for putting this idea in my head!

Badge +2
Do you think it's possible to just put the object instance ID into the _K2.ExtraInfo field?  If this field is part of the XML that is persistent throughout the process, then the approval InfoPath form should be able to get that ID and instantiate the correct object from the database by using the _K2.ExtraInfo as an index.  What do you think?
Badge +7

Yeah, sounds like it might work, however you should bare in mind that the ExtraInfo field may get used by some other part of K2 blackpearl, i'd wait until on the of the K2 guys on here reply with a definitive answer.


I suspect that the extra info field would differ from form to form, so altering this on one form would not impact on the other.


 Creating a hidden field on the form shouldnt be too difficult though.


Martin

Badge +2

For some reason, if I stuff something into the extra info field in the invoice creation step, when the invoice approval infoPath form opens up, the extra info is not available.


 Since  I'm trying in the approval screen to retrieve the same data I stored in the creation screen, I am relying on  being able to  keep the Invoice ID consistently throughout the workflow.  Isn't there a way to do this without code?


 


alex


 


 

Badge +7

Have a read of this thread http://k2underground.com/forums/thread/21787.aspx


I'm sure the solution in there will help you do exactly what you need. I don't think using the 'extrainfo' field is a clean implementation.


Martin

Badge +3

Trying to do somethng similar to the person that initiated this thread.


Was there a solution to this that did not involve splitting XML inside code behind?


I don't understand the point of having all these wizards and SmartObjects and other overheads, if at the end of the day, I still have to break open some code.  If I am already associating the SmartObject Id with a K2 Workflow DataField, and I am storing the returned value from the SmartObject Create method in a hidden field on the InfoPath Form, why can't I just assign that value to some _K2 object somewhere.


If I have to write code for some of it, why wouldn't I just do it for all of it.  It's more confusing for the next developer that takes over my code, if I have half my code assigned via a Wizard GUI and the other half tucked away inside some code layer.


Rather have all one way only.  Then on the handover, its just a matter of, all form values are assigned here, this way.


I also have a support request to give me an example of this, if I get an answer from that I will be sure to post it.  In the mean time, if anyone has some suggestions/examples it would be great.

Badge +3

Looks like from the tests that I have run, and the response from K2 Support, there is no way around it.
Seems that you have to split the XML, after you have submitted the InfoPath Form, in a server event, and then assign that value to a K2 DataField.


Then to parse that value back to the InfoPath Task Form, you need to do the reverse.  In the code behind the InfoPath Form Activity, you need to split the XML Schema of the form, and parse the DataField value in to a datasource field.


The rest of the assignments can be done through a nice wizard or on the InfoPath Form(s) itself.  It's all very disjointed.  But doesn't seem to be a way around it if you wish to deal with InfoPath, SharePoint and K2 together.

Reply