locked
Feature/Workflow to take data from repeating table in Infopath 2007 form and add items to MOSS 2007 list RRS feed

  • Question

  • Hello everyone,

    Well, I first let me start by saying that while I can make sense of peoples code and for the most part can take a basic example in C# and extrapolate a bit to make it work..I am NOT a C# dev. That being said what I am trying to do is figure out a way to create a sharepoint workflow in Visual Studio that will fire when a new item is added to an infopath form library and create new items in a sharepoint list that already exists.

     

    Basically I have a 2007 infopath form in a sharepoint 2007 form library. This form has a repeating table sectoin at the bottom where people can add numerous items. When they submit the form I want a workflow to fire off and take the data from those rows in the repeating table and add new items to an existing sharepoint list.

     

    I have been able to get this working using values from the main body of the form using this example and modifying it to match my environment...

    http://www.bizsupportonline.net/infopath2007/how-to-use-visual-studio-workflow-submit-data-infopath-form-sharepoint-list.htm 

    However, I need something that fits withing that framework but is geared for looping through the repeating rows in the table section?

    I don't know enough about infopath forms crom a code standpoint to know what I'm missing here...

    can anyone help?

     

    Basically I just need an example of what to put and where withing the example listed in that walkthrough or even what to replace in that walkthrough with something else. I'm thinking it's something really simple that any "dev" could do in about 30 secs flat but that I'm just not seeing.

    Thank you so much in advance for you help :-)

     

     

     

    Thursday, April 28, 2011 9:02 PM

All replies

  • Hi,

    Please have a look at my reply on the following thread. Does this help? Please reply back here.

    http://social.msdn.microsoft.com/Forums/en-US/sharepointinfopath/thread/4974d3e5-c987-46df-89b1-e0914eb6a5f8

     


    Pman
    http://www.pmansLab.com/
    • Marked as answer by Emir Liu Thursday, May 5, 2011 7:42 AM
    • Unmarked as answer by Jweiand Thursday, May 5, 2011 2:34 PM
    Thursday, April 28, 2011 11:29 PM
  • First of all I am sorry this has taken me so long to get back. I have been very busy unfortunately/fortunately. I was able to get what I needed working with a bit of help from a dev co-worker and some re-writing of my code.

    To answer your post. No, neither of those two options will work. Or as least not that I am aware of because of an apparent limitation in the receive connections to a list through Infopath.

    I do not want to add code to my forms from the start as I am wanting to make sure the process for submitting the forms never involves an administrator approval process. Supervisor approval via a workflow is fine...but admin approval is not acceptable in this environment. Plus it adds a level of complexity when I am troubleshooting the forms as we have users that will be hitting this remotely and not accross a vpn. So, no code in the forms please thank  you very much :-)

    Second, I can't use the CAML/receive connector solution as some of the fields I need are going to be updating rich text or enhanced richtext columns in a list. These colums do not show up in the dataconnection wizard when creating new recieve connections.

    So, no neither of the solutions you linked me to will work. I appreciate the effort though.

    As an aside or thought or whatever, I don't quite get why it seems so many people on this forum seem to ignore a request for help with a code solution and immediately seem to offer a non-code solution. I mean, it would make sense if someone said "hey can you help with my code OR offer me a non-code work around?" but I rarely see that...what I see are people that have already found the non-code work arounds and determined they wont work. So they need help with code, ask for it...and are offered non-code work arounds...then they have to explain, as I did above, why the work-around wont work...and then wait for someone to hopefully reply to their original request...it's very bizarre to me. Kind of insulting too. Like if someone came up and asked me to do something specific for them and I was like...hmm...no...but I'll do this OTHER thing for you because it will work better...they'd think I was pretty arrogant if I did that without asking them if they had a good reason to want what they asked for anyways.

    Think about this scenario...you're tired, been up all night and look like it! You head down to the local coffee shop and ask for a cup of black coffee...the person dissappears, comes back and hands you a Monster...They don't know you're diabetic, have an allergy to something in it etc...because they didn't ask...they just thought they new best and gave you something other than what you asked for. Then you have to, tell them that no, in fact you can't drink the Monster, explain why, and then ask for a cup of black coffee again...kinda of a pita. I don't know, maybe I"m just in need of a Monster myself atm...last night was a long one... I'll post my code below(minus the stuff for attaching files to the repeating table rows as this requires creating a couple of additional cs files)

    Not a shot at you at all. I very much appreciate the links and the reply. You are the only one that replied after all and I am grateful for it!

    It's just something that irks me and I'm kinda hoping others will read this and think about that when they are replying to people in need.


    Jason
    Thursday, May 5, 2011 2:34 PM
  • Now, like I said...I'm not a programmer so I'm sure this is sloppy as all get out and I do appologize for that...but this is what got me working
    
    
    And, now that this is done, it's cake to add more to this form and replicate this structure to get the workflow to do more...for example, I can
    
    
    add the ability for users to enter lists or groups of poeple to notify and have this workflow either trigger a basic notification workflow or just do
    
    
    it itself, check for other stuff in the list and do comparisons againsts other lists, update related values in other lists, or delete deprecated list
    
    
    list items all kinds of stuff...it will all be done on the server where I don't have to worry about limitations of different netbooks and the like as
    
    
     far as connection speeds and available memory for the browser etc...
    
    






    public
    void codeActivity1_ExecuteCode(object sender, EventArgs e)

        {

          // Retrieve the file associated with the item

          // on which the workflow has been instantiated

          SPFile file = workflowProperties.Item.File;

     

            if (file == null)

            return;



         

          byte[] xmlFormData = null;

          xmlFormData = file.OpenBinary();



         

          XPathDocument ipForm = null;



          if (xmlFormData != null)

          {

            using (MemoryStream ms = new MemoryStream(xmlFormData))

            {

              ipForm = new XPathDocument(ms);

              ms.Close();

            }

          }



          if (ipForm == null)

            return;





          // Create an XPathNavigator object to navigate the XML

          XPathNavigator ipFormNav = ipForm.CreateNavigator();

         

          XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());

         

          //This was a bit of a pain...I don't know why "my" wasn't showing as defined but it wasn't

          //and I had to add this in anyways...meh, Microsoft.

          nsManager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-04-05T23:10:25");



          XPathNodeIterator rows = ipFormNav.Select(

            "/my:myFields/my:group1/my:EventsRepeatingTable", nsManager);



          ipFormNav.MoveToFollowing(XPathNodeType.Element);





          foreach (KeyValuePair<string, string> ns

          in ipFormNav.GetNamespacesInScope(XmlNamespaceScope.All))

          {

            if (ns.Key == String.Empty)

            {

              nsManager.AddNamespace("def", ns.Value);

            }

            else

            {

              nsManager.AddNamespace(ns.Key, ns.Value);

            }

          }



          string nTitle = string.Empty;

          string nPlanNumber = string.Empty;

          string nDueDate = string.Empty;

          string nDescription = string.Empty;

          string nEventsReason = string.Empty;

          string nEventsStatus = string.Empty;

          string nAffectsDropDowns = string.Empty;

          string nAssignedTo = string.Empty;

          string attachedfile = string.Empty;

         



        



          List<string> l = new List<string>();

            using (SPSite site = new SPSite("Http://Mysite.net"))

            {

              using (SPWeb web = site.OpenWeb())

              {

                SPList list = web.GetList("/Lists/PCRTasks");

               

                if (list != null)

                 

                  {

                   

                    XPathNodeIterator navi = rows.Current.SelectSingleNode("//my:group1", nsManager).SelectChildren(XPathNodeType.Element);

                    while (navi.MoveNext())

                    {

                      XPathNodeIterator xpn = navi.Current.SelectChildren(XPathNodeType.Element);

                      while (xpn.MoveNext())

                      {

                        string value = string.IsNullOrEmpty(xpn.Current.Value) ? string.Empty : xpn.Current.Value;

                       

                        switch (xpn.Current.LocalName.ToLower())

                        {

                          case "eventsplannumber":

                            nPlanNumber = value;

                            break;

                          case "eventspcrduedate":

                            nDueDate = value;

                            break;

                          case "richtextdescription":

                            nDescription = value;

                            break;

                          case "reason":

                            nEventsReason = value;

                            break;

                          case "status":

                            nEventsStatus = value;

                            break;

                          case "affectsdropdown":

                            nAffectsDropDowns = value;

                            break;

                          case "user":

                            nAssignedTo = value;

                            break;

                          case "fileattachment":

                            attachedfile = value;

                            break;

                        }

                      }

                      InfoPathAttachmentDecoder decoder =

                      new InfoPathAttachmentDecoder(attachedfile);

                      byte[] attachment = decoder.DecodedAttachment;

                      string fileName = decoder.Filename;

                      SPUser user = web.EnsureUser(nAssignedTo);

                      SPListItem item = list.Items.Add();

                      item["Title"] = file.Item.ID.ToString();

                      item["Plan_x0020_Number"] = nPlanNumber;

                      item["DueDate"] = nDueDate;

                      item["Body"] = nDescription;

                      item["AssignedTo"] = user;

                      item["Reason"] = nEventsReason;

                      item["Status"] = nEventsStatus;

                      item["AffectedItems"] = nAffectsDropDowns;

                      item.Attachments.Add(fileName, attachment);

                      item.Update();

                     

                    }



                   



                   



                   



                   

                }











                web.Close();

              }

              site.Close();



            }

          }


    Jason
    Thursday, May 5, 2011 2:48 PM
  • So what was your final solution.

    Can you post it for the rest of us?

    Thanks!


    ______________ Aaron Hamilton
    Friday, September 2, 2011 2:44 PM