executeAction not working.. WHY WHY WHY? - InfoPath Dev
in

InfoPath Dev

executeAction not working.. WHY WHY WHY?

Last post 02-14-2007 12:43 PM by Greg Collins. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 02-09-2007 11:34 AM

    executeAction not working.. WHY WHY WHY?

    Hello All,
    New to infopath and using infopath 2007. I am extremely frustrated right now to lack of support online for this product but can see that it's valuable once I can get past these growing pains. I hope someone can help, i've been looking at this same problem for DAYS and can't get it to work.
    So i have an infopath form, there is a repeating group with 1 field with 2 attributes on it. In essence it looks like
    <my:Images>
    <my:Image my:Type='type' my:Id='id'></my:Image>
    </my:Images>

    My form is hosted in a windows forms application using C#. What i want to do is dynamically through code add the Image children to the Images parent in the underlying XML. This seems to be IMPOSSIBLE and I am wondering if anyone knows how to do this?

    i have tried appending a new XML node to the parent node using appendChild.. this way gives me a "Schema validation found non-data type errors" error and i have no idea what this means and what i can do to prevent it and make it work.

    i have tried using the currentView.ExecuteAction method and with that i get the error "The specified varXmlToEdit value for the View.ExecuteAction call is not valid" OR I GET THE ERROR "Either the combination of values for the
    View.SelectNodes call is an invalid selection, or the values are not defined for..." i get this error if i try and select the node i want to append to prior to using executeAction.

    Does anyone know anything that may help me????
    Thanks
    this view, defined for this view more than once, or not selectable in the view."
  • 02-09-2007 12:03 PM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    Now I am getting this error

    The specified bstrAction value for the View.ExecuteAction call is not applicable for the current selection

    when i use executeAction.. here is the code:

    formControl1.XmlForm.CurrentView.ExecuteAction(Microsoft.Office.InfoPath.ActionType.XOptionalInsert, Constants.IMAGES_XMLTOEDIT);

    where Images_XmlToEdit = Images_128
  • 02-09-2007 12:14 PM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    ExecuteAction is flaky at best. I say this because there are too many restrictions on when and where it can be used.

    I you want to insert nodes into your DOM from code, just do it directly by creating the nodes in code, and then appending, or inserting them where they should go.

    If you need help creating and adding nodes to a DOM, Visual Studio help should be able to get you what you need.
  • 02-09-2007 12:17 PM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    Hi Greg,
    I've tried to append nodes to the DOM as you suggest however i continue to get this error:

    "Schema validation found non-data type errors"

    When i do.. here is the code i use:

    string temp = createChildNode(pair);
    XmlReader reader = XmlReader.Create(new StringReader(temp));
    formControl1.XmlForm.MainDataSource.CreateNavigator().SelectSingleNode(Constants.IMAGESGROUP, xmlnsm).AppendChild(reader);


    private string createChildNode(KeyValuePair<Guid, string> pair)
    {
    //write get the XML of repeating node into a string
    XmlDocument document = new XmlDocument();

    XmlNode oElement1 = document.CreateElement("my:Image", xmlnsm.ToString());
    XmlAttribute typeAttribute = document.CreateAttribute("my:Type", xmlnsm.ToString());
    typeAttribute.InnerText = pair.Value;

    XmlAttribute idAttribute = document.CreateAttribute("my:Id", xmlnsm.ToString());
    idAttribute.InnerText = pair.Key.ToString();

    oElement1.Attributes.Append(typeAttribute);
    oElement1.Attributes.Append(idAttribute);

    document.AppendChild(oElement1);

    return document.DocumentElement.OuterXml;
    }
  • 02-09-2007 04:36 PM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    After creating the XmlNode (oElement1), you should be able to directly append it to your DOM... not sure why your returning the OuterXml, etc.

    Also, you need to make sure that your element is created using the same namespaces as your DOM you want to insert it into. It looks like you are probably doing that, but you need to make sure because you are creating a new XmlDocument, rather than creating the node using the MainDataSource DOM.

    Sorry if confusing... I've had little experience so far using the 07 OM... I'm still spending most all my time building 03 forms for work.
  • 02-12-2007 01:37 PM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    Hi Everyone,
    I ended up having to call Microsoft on this one. The repeating table I had was inside an optional section on my form. It turns out you cannot add nodes programmatically to optional sections, i turned my option section into a regular section and all works as it should.
    Erin
  • 02-13-2007 05:01 PM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    I'm glad you got it working, however I would like to make a corrective statement:

    You can programmatically add them to an optional section -- provided the optional section exists in the DOM (i.e. it's optionally THERE as opposed to optionally NOT THERE).

    However, as stated ealier, do not try to use 'ExecuteAction'. Instead build the nodes in code, and then append them or insert them as appropriate.
  • 02-14-2007 06:12 AM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    The weird thing about that though Greg is that the optional section DID exist in the DOM and it was a part of my form??!!
  • 02-14-2007 10:56 AM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    Hi ErinSelena,
    So isn't that what Greg is saying? I think you got the easy advice from MS. This is doable, but perhaps not worth the trouble since you have a workaround... :)
    Patrick Halstead
    Project Manager at Qdabra
  • 02-14-2007 11:15 AM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    I thought Greg was saying that you can programmatically add a node to an optional section as long as it exists in the DOM. What i was saying is that my optional section DID exist in the DOM however I could not programmatically add nodes to the xml. It wasn't until (upon Microsofts advice) I changed my optional section to a regular section, that i could programmatically add nodes to the DOM.
    Anyways it works now, so i am happy.
  • 02-14-2007 12:43 PM In reply to

    Re: executeAction not working.. WHY WHY WHY?

    Hi.. again, I'm glad you got it working, and not having it as optional is a satisfactory solution, then there's no sense going back to it at this point.

    I'm not exactly sure why it wasn't working for you--I just know that I do this kind of stuff all the time and have never had such issues. All I can think is that there was some other issue involved which would need to be debugged to find out why it wasn't working.

    Thanks for sharing your solution, it might prove useful to another in a similar situation!!
Page 1 of 1 (11 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.