New to Infopath with a question on managed code - InfoPath Dev
in

InfoPath Dev

New to Infopath with a question on managed code

Last post 05-20-2010 08:53 AM by Flanker. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 05-18-2010 10:20 AM

    New to Infopath with a question on managed code

    I have a form with 2 data connections, email and sql database. On submitting the form using the submit button on the toolbar it works just fine.  I use 'custom action rules' in the submit options.  Also a pop up message is displayed (using C# managed code that is triggered when one of the required fields on the form is filled out), once the user clicks the ok button on the pop up message both data connections then submit just fine.  That is the flow and what I want.   

    My problem is now I must add a submit button to the form itself while maintaining the same flow as above.  The submit button on the form works just fine when submitting the email and sql data sources using the 'rules and custom code' option.  But when I try to display the pop up message before submitting the form, I have to click the submit button twice, once to generate the pop up message and once to submit the data connections.   Also the "form submitted successfully" message is not being displayed when the form is submitted to the sql database. 

    The control flow of the form behaves differently when using the submit button on the toolbar versus using a submit button on the form. 

    My solution was to use the 'submit' action on the button property on the form and do this entirely in managed code, C# using the 'Perform custom action using Code'. 

    I can display the pop up message, then send the email but am unable to submit to the sql database even though I get the  "form submitted successfully". 

    Here is the code for the data connections;

    EmailSubmitConnection ec = (EmailSubmitConnection)(this.DataConnections["Email Submit"]); 

    DataConnection mc = (DataConnection)this.DataConnections["Main connection"];

    try{ ec.Execute(); e.CancelableArgs.Cancel = false;} catch {e.CancelableArgs.Cancel = true;}

    try{ mc.Execute(); e.CancelableArgs.Cancel = false;} catch {e.CancelableArgs.Cancel = true;}

     

    Any help will be greatly appreciated, Sorry I don't know how to use the tags yet. 

     

     

     

     

      

  • 05-18-2010 11:36 PM In reply to

    Re: New to Infopath with a question on managed code

    when we use managed code to submit the form, it is our responsibility to let the form know whether the submittion was sucessfull or not. we do this by settign the

    CancelableArgs.Cancel to true or false.

    try getting both the submits in only one try, so that if one fails the other doesnt execute. also no need to set the cancelableargs.cancel to true.

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 05-19-2010 08:03 AM In reply to

    Re: New to Infopath with a question on managed code

    Thanks Qazi,

    But what is the correct code to use to submit my main connection,  up to this point I have not been successful except submitting the email connection.

    Thanks

  • 05-19-2010 08:15 AM In reply to

    Re: New to Infopath with a question on managed code

    use 

    FileSubmitConnection fc = (FileSubmitConnection)this.DataConnections["Main submit"];

    fc.Execute();

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 05-19-2010 08:42 AM In reply to

    Re: New to Infopath with a question on managed code

    I add the code as you suggest, but when I step through in debug, the fc.Execute() is never executed. I get a system error message "Infopath cannot submit the form. The OnSubmitRequest event handler returned a value indicating that the submit failed."

    my code is this;

    try{

    FileSubmitConnection fc = (FileSubmitConnection)this.DataConnections["Main submit"];

    fc.Execute(); // this statement code never getting executed
    e.CancelableArgs.Cancel=false;

    }

    catch{

    e.CancelableArgs.Cancel=true;

    }

  • 05-19-2010 11:04 PM In reply to

    Re: New to Infopath with a question on managed code

    try this.DataConnections["Main connection"].Execute();

     if that doesnt work check this


    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 05-20-2010 08:53 AM In reply to

    Re: New to Infopath with a question on managed code

    I had tried that code already, it compiles and executes without error and even the 'From submitted successfully" message displays,  except that it does not update the database.  I guess this is not possible to update the sql database using managed code using Microsoft.Office.InfoPath namespace classes and methods?

    Thanks

     

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