Infopath work flow, retrieve initial values of form

  • 27 March 2008
  • 7 replies
  • 0 views

Badge +3

I have an Infopath wf and I want to get the initial values submitted on the IP form.  I've tried using the following:


K2.ProcessInstance.XmlFields[

"MyTemplate"].Value -> this just gives the document with no xpath values, it's a blank form.


 K2.ActivityInstanceDestination.XmlFields["MyTemplate"].Value  -> this always gives an error that the template/key cannot be found, not valid xml field


 The above calls are made in Server Events (code).


I'm basically wanting to log the changes of the fields of the IP form in each activity to an external database for reporting purposes.


 Thanks,


 Scott


 


7 replies

Badge +9
I think I can help you here, as it appears as if you are trying to do something that we do over here as well.  Maybe you can give me a little bit more detail - does your process begin with the submission of an InfoPath form?  Can the InfoPath activites be worked on by more than one person at a time, or only one person is opening and editing the InfoPath forms?
Badge +3

Yes it begins with a submission form.


And, only one person is opening and editing the InfoPath form in an activity.


Let me know if you need more info.


 Thanks,


Scott

Badge +9
Ok, good... when setting your destination for each activity, back up the destination wizard to the first screen and select 'advanced'.  I don't have the exact screen in front of me right now, but in advanced mode you should be able to specify 'plan all at once' and to have just one slot for the activity.  With things set up this way, the ActivityInstanceDestination approach to getting your xml should work.  Give this a shot, I am not able to verify right now but it should be a step in the right direction.
Badge +3

Okay, I set that option.


Just to clarify, all I want to do is get the form values from the IP form before and after each activity.  I would figure this would be a very simple thing to do.  The process instance has the xml but all the xml tags don't have the form values.  Is this a wrong context issue or something?


I really just need to know what is the way to get at the unmodified/modified form values in an IP form during a workflow via BP object model.


 Scott

Badge +9
The process instance XML still doesn't have the values after setting plan all at once with one slot?  Please verify this... we use the process instance xml values all over the place in our processes, so I can say for a fact that this should work.  If it isn't working, I'll try and help you get to the bottom of it.
Badge +3

I went through and verified that everything was set, and still during the ServerEvent (code) I get the xml with no data in the tags. 


So here's what I did instead,


1) I removed the ServerEvent's and undid the changes instructed above back to the defaults


2) put the custom code to call the external .dll at the end of setProperties_ExecuteCode in the InfoPath Client Event. 


This works perfectly, I'm able to retrieve the initial values of the form using K2.ProcessInstance.XmlFields[_xmlFieldName].Value.  The wizards don't look to be regening the code in this method when settings are changed, so it doesn't look like I will lose my changes.


Are there any drawbacks to doing it this way?


Scott

Badge +3

Don't know what I was doing wrong but I just copied the way the BP gen'd code does it and it worked in the Server Event:


XmlField field = K2.ProcessInstance.XmlFields["WireTransferTemplate"];


string fieldValue = field.Value.Trim();


XmlDocument doc = new XmlDocument();


doc.PreserveWhitespace =

true; // necessary otherwise break digital signatures


doc.LoadXml(fieldValue);


XmlNamespaceManager nm = new XmlNamespaceManager(doc.NameTable);

nm.AddNamespace(

"my", doc.DocumentElement.GetNamespaceOfPrefix("my"));


int val = int.Parse(doc.SelectSingleNode("/my:myFields/my:WireDirectionID", nm).InnerText);

Reply