Using code and rules- Can I print and submit form with one button click? - InfoPath Dev
in

InfoPath Dev

Using code and rules- Can I print and submit form with one button click?

Last post 06-27-2012 08:14 AM by Doreen. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-26-2012 10:52 AM

    • Doreen
    • Top 50 Contributor
      Female
    • Joined on 08-11-2010
    • Federal Way, WA
    • Posts 291

    Using code and rules- Can I print and submit form with one button click?

    I am using IP 2007.  It seems if I have simple code behind  like:  this.print(); on a button control and rules on the same control, only the rules run??

    Ideally I'd like to print and submit with one click but my submit rules need to set several other field values first. My form is submitted correctly but the print method is ignored.  

    I tryed coding a message box in the button control with the submit rules to ask the user to print instead but that behaves the same as if I'd just coded this.print();.  So it seems to me no matter what code I give it, it is ignored.  If I put the code alone on a separate button control, it works just fine.

    So my question is - is there a way to throw code and rules into action on one control - preferably a button control?

  • 06-27-2012 04:24 AM In reply to

    Re: Using code and rules- Can I print and submit form with one button click?

     Hi-

    Rules execute before code, so the rules are executing, the form is submitted, perhaps closes, and then the Print command has no chance to execute.

    You could add a node to your form schema and add to it the rules that you want to run after code. Your button (without rules) will now call the code only. Then after all your code has executed, have the code set the value of the new node (the one that now has all the rules). This will be the trigger on the new node to execute the rules.

    Good luck!

    Ernesto Machado
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™


  • 06-27-2012 08:14 AM In reply to

    • Doreen
    • Top 50 Contributor
      Female
    • Joined on 08-11-2010
    • Federal Way, WA
    • Posts 291

    Re: Using code and rules- Can I print and submit form with one button click?

    Thank you - after a little research I figured out that rules run before code.  My rules were ending with submit and close which was why the printing didn't happen. 

    I like your idea and I would be interested how to write c# code to set a value on a node (like a button?) because it may be the solution to my newest problem.  In the meantime I took out the submit action rules which included closing the form, and left in the rules which populated the other fields.  Now I programmatically submit the form:

    On the button click event, after the print call, I call a method to submit the form (FormEvents_Submit()) and it workswith warning exception error which I catch using try/catch.  It doesn't stop the form from printing or submitting "an object reference is not set to an instance of an object" which I should investigate more....

    ---edit: I removed the rest of this post because it relates to a different problem. Will post a new thread for it.

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.