Updating an element right before submitting - InfoPath Dev
in

InfoPath Dev

Updating an element right before submitting

Last post 01-13-2009 11:56 AM by admot. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-08-2009 09:12 AM

    • admot
    • Top 500 Contributor
      Male
    • Joined on 08-09-2006
    • USA
    • Posts 51

    Updating an element right before submitting

    I would like to update an element right before the person uses the Submit button used in Tools\Submitting forms. I figured I'd use OnSubmitRequest.

    function XDocument::OnSubmitRequest(eventObj)

    {

     XDocument.DOM.selectSingleNode("my:...").text = XDocument.Errors.Count;

    }

     

    But for some reason, it doesn't update it on a submit. Is my code too simplistic? I did a search in the forums but didn't find anything. I'm updating an element to count # of errors, because the form can be submitted also via email attachment and I have a webservice checking for IPFormError.

    Any help is appreciated. Thanks,

    Don't grow old regretting the things you didn't do.
  • 01-08-2009 02:58 PM In reply to

    Re: Updating an element right before submitting

    Do you need to use code for this?  It's a built-in feature with a checkbox on the Browser tab of the Form Options menu.  If your form is not browser-enabled, I would think you could add a Refresh rule to your Submit "button" that refreshes any or all data connections before the submit action itself.

  • 01-13-2009 10:31 AM In reply to

    • admot
    • Top 500 Contributor
      Male
    • Joined on 08-09-2006
    • USA
    • Posts 51

    Re: Updating an element right before submitting

    warrtalon:

    Do you need to use code for this?  It's a built-in feature with a checkbox on the Browser tab of the Form Options menu.  If your form is not browser-enabled, I would think you could add a Refresh rule to your Submit "button" that refreshes any or all data connections before the submit action itself.

     

    I'm using IP 2003 and I didn't see that option available. There will already be a submit button at the top of the form where it submits via email data connection. Since it was a requirement to use the Data Connection, having two submit buttons would confuse the user.

     

    I think I figured it out but there's still a problem:

    1) Instead of submitting to email, submit via code.

    2)  Use the following code:

     XDocument.DOM.selectSingleNode("my:....").text = XDocument.Errors.Count;
     XDocument.DataAdapters["ExtranetSubmit"].Submit();

    This seems to work fine. But if I cancel the submit, I get an error back stating it was cancelled. Is there an error handle I can place in where if they cancel, it will just accept the cancel?

    Don't grow old regretting the things you didn't do.
  • 01-13-2009 11:56 AM In reply to

    • admot
    • Top 500 Contributor
      Male
    • Joined on 08-09-2006
    • USA
    • Posts 51

    Re: Updating an element right before submitting

    I believe I found a way. Just use try/catch. I also had to turn off the default message via Submitting Forms\Submit Options. Strange that it shows an error if the person cancels but so be it.

     try
     {
      XDocument.DataAdapters["SubmitviaEmail"].Submit();
      XDocument.UI.Alert("The form was submitted successfully.");
     
      // Setting ActiveWindow.Close to true will close InfoPath immediately. Setting to false prompts to save the form.
      Application.ActiveWindow.Close(true);
     }
     catch(e)
     {
      XDocument.UI.Alert("The request has been cancelled.");
     }

    Don't grow old regretting the things you didn't do.
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.