Am I on the right track with ExecuteAction - InfoPath Dev
in

InfoPath Dev

Am I on the right track with ExecuteAction

Last post 01-16-2006 08:00 PM by Matt Faus. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 01-13-2006 02:00 PM

    • Ethan
    • Not Ranked
    • Joined on 01-13-2006
    • USA
    • Posts 4

    Am I on the right track with ExecuteAction

    As a non-programing newcomer to InfoPath I'm in way over my head with something that appears to be very simple. I need to know if I'm askingt a stupid question or if I'm on the right track.

    I've gone through Introducing MS Office InfoPath and Developing Solutions with MS InfoPath as well as this and other InfoPath forums and sites and found bits and pieces to solve my problem but I can't seem to put them all together.

    Here's my predicament:

    My form queries an Access db and returns a list of subcontractors. After the query results are returned I need to insert a blank row inside a repeating table which is inside the primary repeating table where the subcontractor query results are returned. Asking the user to insert each new row is too cumbersome so I'm trying to do it with code.

    So far I've learned about and experimented with <XDocument.View.ExecuteAction("xCollection::insert","xmlToEdit");> and SelectNodes, and SelectSingleNode which appear to be all that I need. So far I've been unsuccessful at combining them as well as determining how to trigger the code after the query results have been returned. I could use a button but having it work automatically would be better for the user.


    Can anyone please help?

    Best regards,
    Ethan

    EParker @ FuzzyLogic
  • 01-13-2006 02:46 PM In reply to

    Re: Am I on the right track with ExecuteAction

    Well your first problem is thinking that you cannot do it, you CAN!
    See this code for easily adding a blank row:
    var oRow = XDocument.DOM.selectSingleNode("/my:myFields/my:Table/my:Row");

    XDocument.DOM.selectSingleNode( "/my:myFields/my:Table" ).appendChild( oRow.cloneNode(false) );


    As for running the code after your query finishes - you should be able to simply put the lines of code to insert the blank row underneath the Query() line and it will run after it finishes. The script doesn't run statements simultaneously, it runs them linearly.

    Hope this helps, let us know if you need any more help!


    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-13-2006 09:57 PM In reply to

    • Ethan
    • Not Ranked
    • Joined on 01-13-2006
    • USA
    • Posts 4

    Re: Am I on the right track with ExecuteAction

    Matt, thanks for your response. I appreciate the help.
    I'm getting a run-time error "'null' is null or not an object" with the code you pro recommended. The error is in the second line. I've included it below. I've researching this on my own on MSDN and here but I'm not having any luck. Your wisdom would be much appreciated.

    var oRow = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Projects/d:PrjctTrds/d:Scores/d:Scr");
    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Projects/d:PrjctTrds/d:Scores").appendChild( oRow.cloneNode(false) );


    Thanks again,
    Ethan

    quote:
    Originally posted by MFaus

    Well your first problem is thinking that you cannot do it, you CAN!
    See this code for easily adding a blank row:
    var oRow = XDocument.DOM.selectSingleNode("/my:myFields/my:Table/my:Row");

    XDocument.DOM.selectSingleNode( "/my:myFields/my:Table" ).appendChild( oRow.cloneNode(false) );


    As for running the code after your query finishes - you should be able to simply put the lines of code to insert the blank row underneath the Query() line and it will run after it finishes. The script doesn't run statements simultaneously, it runs them linearly.

    Hope this helps, let us know if you need any more help!


    ---------------
    Matt Faus
    InfoPath Dev Texas




    EParker @ FuzzyLogic
  • 01-14-2006 10:05 AM In reply to

    Re: Am I on the right track with ExecuteAction

    When you get that error it almost always means that your XPath is wrong. When connecting to a database, I don't think you need the d: namespace before every node, so try this:

    var oRow = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Projects/:PrjctTrds/:Scores/:Scr");
    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Projects/:PrjctTrds/:Scores").appendChild( oRow.cloneNode(false) );

    If that doesn't work take out the colons in the last three nodes of the first statement and the last two nodes of the second statement.

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-16-2006 09:15 AM In reply to

    • Ethan
    • Not Ranked
    • Joined on 01-13-2006
    • USA
    • Posts 4

    Re: Am I on the right track with ExecuteAction

    Matt, I was able to get your code to work but only in after I set up a rudimentry test project and I had to change the XPath in the first line to point to a repeating group instead of a field.

    	
    var oRow = XDocument.DOM.selectSingleNode("//my:employees/my:employee");
    XDocument.DOM.selectSingleNode("//my:employees").appendChild( oRow.cloneNode(false) );


    Unfortunately I haven't found the right XPath in my actual project to make the code work. I've looked up other examples of code that use XPaths but I haven't had any success understanding the logic well enough to apply them to my work.

    If I create a new function, eg OnContextChange, InfoPath writes the XPath of the control you are creating the code for into the comment area. For the control that I need to clone the XPath is "/dfs:myFields/dfs:dataFields/d:Projects/d:PrjctTrds/d:Scores". I tried your suggestion of removing the colons which gave me the same error I've been getting. Endless trial-and-error hasn't yielded any positive results either.

    Do you have any other suggestions on the correct XPath I should be using?

    Thanks,

    EParker @ FuzzyLogic
  • 01-16-2006 05:10 PM In reply to

    Re: Am I on the right track with ExecuteAction

    If you are using the connection to a database it might be that the nodes you are trying to access are attribute nodes. This would require you to put a '@' in front of the name to specify them. Try this:

    var oRow = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Projects/PrjctTrds/Scores/@Scr");
    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Projects/PrjctTrds/Scores").appendChild( oRow.cloneNode(false) );

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-16-2006 07:56 PM In reply to

    • Ethan
    • Not Ranked
    • Joined on 01-13-2006
    • USA
    • Posts 4

    Re: Am I on the right track with ExecuteAction

    Matt, I gave that a try and got an error indicating something about the action not working on an attribute. Simply because of a very near deadline I had to solicit the professional services of Atonomy Systems. Greg Collins wrote some code that used appendChild and employeed some other methods. I only mention this to provide anyone who reads this thread with as a point of conclusion.

    This forum is absolutely indespensible an thank you agian for your help.

    Ethan @ FuzzyLogic
  • 01-16-2006 08:00 PM In reply to

    Re: Am I on the right track with ExecuteAction

    Well, sorry we couldn't figure it out through the forum, but I'm glad it's working now. Greg is quite a whiz.

    Let us know if you have any other questions!

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.