SAVE form using button control - InfoPath Dev
in

InfoPath Dev

Having trouble finding a blog or post that answers your question? Check out our Custom Search Page

SAVE form using button control

Last post 05-23-2013 09:04 AM by Ace07. 15 replies.
Page 1 of 2 (16 items) 1 2 Next >
Sort Posts: Previous Next
  • 12-22-2008 01:14 PM

    SAVE form using button control

    I have a form that submits data to an access database on a network harddrive. I am not connected to Sharepoint or anything else. Users open the form from a network drive, complete the form, submit the data using a button at the bottom of the form. The data is written to the Access database also on the server. Then, we import the data from Access to SPSS for data analysis.

     I would like to include a button at the bottom of the form that allows the user to save the form and its data to a common network folder. I would like the save button to include a default file name for the form that is a combination of two fields on the form/database. I have come across many references to this sort of thing, but none have been very clear and most included using Sharepoint or webservice.

    I am new to coding and need explicit directions (if coding is needed). It seems that the slightest modification to my form's code can cause it to become corrupt and unusable, so I'm hesitant to experiment.

    Any help is appreciated.

    Thank you.

  • 12-23-2008 02:08 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: SAVE form using button control

    Hello,

    The following steps will walk you through to solve your problem

    1. Open form in design mode
    2. Go to Properties window of button
    3. Click on 'Edit Form code' button
    4. Write the following code in 'OnClick function'

    Xdocument.Save();


    And the form must be full trust, not just from the same domain.
    Marking the form as coming from a Trusted Site is not sufficient.

    You can make the form fully trusted by:
    A) Registering it on each user's computer using an msi, or jscript file.
    B) Digitally signing the form (SP1 only)

  • 12-23-2008 04:45 AM In reply to

    Re: SAVE form using button control

    OK. That worked, but I can't register the form on other computers or digitally sign the form. So, is there a way to have the form specify a file name based on two fields when the user clicks on the "Save" icon on the Infopath menu?

    Thank you.

  • 12-23-2008 10:25 AM In reply to

    Re: SAVE form using button control

    1. Make a second "save" button next to your "submit" button on the form (not the built-in save/submit buttons on the toolbar, but rather custom buttons on the form). The Save button will just be a plain button that you rename and that has rules behind it. 
    2. Behind the Save button, add rules (no code)
    3. Create a new text data element in your main data source named Filename or whatever you prefer.  This is where you will store the concatenated "filename" that you want to use.
    4. Create a rule with the condition that it will only trigger if Filename is NOT blank
    5. The only action will be to "submit to a data connection," and that data connection will either be a new or existing data connection to a network path where you want to save the forms.  That data connection should use the Filename field when naming the file before submission (this is in the last step of the data connection configuration wizard), and it should be set to OVERWRITE IF FILENAME ALREADY EXISTS.  This is the only action in this rule.  Since it's not a browser form, you could also add a pop-up box that notifies the user of a successful "save."
    6. Create a second rule with the condition that it will only trigger if Filename IS blank (should also work if you have no condition, since we put the other rule first)
    7. The first action of the second rule will be to set the filname.  The action will "set value in field" for the filename element and will insert the function "concat(field1,field2)."
    8. The second action will use your network path data connection to submit the file to a network drive using the data connection from step 5.
    9. Change your current submit button so that it also uses this same Filename field to specify its filename upon final submission.

    Doing this, people can Save at any point in time without delay or hassle.  This shouldn't require full trust or managed code.

  • 12-23-2008 12:03 PM In reply to

    Re: SAVE form using button control

    I appreciate the instructions. I am trying to follow your steps as written, but I'm still not getting it to work. Either I am misunderstanding your instructions, or they are written out of order and thus causing issues for me. I have created the "Filename" field and put in the rules, but I don't think I've got the rules in the correct place. Once I insert the button and then double-click to get the "Button Properties" window, what "action" do I select--"submit"? If so, then what do I select in the "Submit to" field of the next window that opens--"custom using rules"?

    Thanks.

  • 12-23-2008 12:17 PM In reply to

    Re: SAVE form using button control

    You don't change the button settings.  You just change the label from "button" to "save" and then add rules by clicking the rules button.  Don't change it to a submit-type button.  This is where you put the rules to create the filename and do the submitting to data connections.

  • 12-23-2008 08:33 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: SAVE form using button control

    Hello,

    In above rules should be order like first is setting file name and then submitting data connection.

    Otherwise you can directly add the default value(combination of two fields data) for field name field.

  • 12-23-2008 09:48 PM In reply to

    Re: SAVE form using button control

    No, the first rule is the submit for a form that has already been submitted once.  You need to make sure it uses the same exact filename from the original submit, and it can only run that rule when the form has been submitted at least once, which is only possible when the filename field is NOT blank.  That's the point of setting the filename in the 2nd rule, because that's when you are actually submitting the form for the first time to the SharePoint library.  The first time you submit the form, it skips the first rule and runs the second rule, which first sets the filename field (hidden field) and then submits to the library using that pre-set filename.  The next time that form is opened, the filename is already set, so ONLY rule 1 runs, and all that does is overwrite the existing file with the new data (same filename).  I don't like to set the filename to a default value, because the fields being used to set the filename may change, which then screws up the whole system.  Set the filename once when it is first submitted and never touch it again.

  • 12-24-2008 06:36 AM In reply to

    Re: SAVE form using button control

    So, if I understand you correctly, I need to have a data connection to a network path where I want to save the forms. Currently, I only have one data connection and it submits my data to the access database on the network drive. To create the second data connection, do I choose "Submit" or "Receive" data? Depedning on my choice, do I then select "Web Service" "Sharepoint Form Library" "XML Document" or "Database"? Those are my choices as I run through the "Data Connection Wizard." I don't have an option to select or browse to a network folder or select a path.

    Thanks.

  • 12-24-2008 07:46 AM In reply to

    Re: SAVE form using button control

    Hmm, well I know you can publish to a network path, so I figured you could submit to one.  What do people do who have it published to a network path and don't have a back-end database nor SharePoint to submit the form to?  I only ever use InfoPath as a direct integration with SharePoint, so I'm not sure which step is involved to have the forms saved directly to a shared directory or whatever.  Are you currently not saving the form itself anywhere and are just submitting the data straight to Access?  I thought you were already submitting the resulting XML form itself to some location, but it now sounds like you're only pushing the data to Access, and there is no leftover InfoPath file anywhere.  Then, I suppose that is why you want to be able to save it to a network drive.  Try the "XML Document" option of the Submit path above, because the resulting form after "submitting" an InfoPath form is truly an XML form (the template is an XSN).

  • 12-24-2008 08:01 AM In reply to

    Re: SAVE form using button control

    Currently, users are submitting the data directly to an access database sitting in a folder on a network drive. Users are also being instructed to save the form to a folder on the network (as a backup incase the database were to crash or corrupt). Users are saving the form simply by clicking "Save" on the toolbar menu and typing in a file name.

    I was hoping to include a button that would simultaneously submit the data and save the form to a folder using a file name that is generated from data in the form (e.g., LastName + ID#). Having this functionality is not critical in order to use the form, but (unfortunately) users do not always do as they are asked, and I am afraid that some users will fail to save the form. Conseuqently, if the database were to ever corrupt, we would lose important information. With each form saved, I could rebuild the database easily should the need arise.

     Thanks.

  • 12-24-2008 08:35 AM In reply to

    Re: SAVE form using button control

    Right.  What I've prescribed would do the trick for you, but instead of two separate buttons, you could put all the rules behind one custom submit button (no code).  The actions in the rule would be like this:

    1. Set a field's value.  Field = Filename (text data element); Value = concat(fields1,fields)
    2. Submit using a data connection (submit's to location)
    3. Submit using a data connection (submit to Access DB)
    4. Close

    Unfortunately, I don't see a way to tell it to publish to a network drive.  If you had SharePoint, this would work great and be very easy, but without SharePoint or another ASP.net hosting app, I don't suppose you can do it with the GUI.  If you can get the Save function from above to work within your custom button to replace step 2 above, then I think you'd be golden.

  • 12-24-2008 03:15 PM In reply to

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 192

    Re: SAVE form using button control

    Merry christmas!

    Does the New ActiveXObject command work for you in code or does it force you to level 3 security? (which is fine I guess if you can do that as well).

    Try the following function
    [jScript]

    function saveFormAsFile()
    {
     var strFileName = "formName.xml"
     var xmlDoc = XDocument.DOM.xml;
     var objFSO = new ActiveXObject("Scripting.FileSystemObject");
     var tempFile = objFSO.CreateTextFile("c:\\" + strFileName , true);
     tempFile.Write(xmlDoc);
    }

    If your form lets you use the ActiveXObject command then this should work for you. But maybe also other security issues in your workplace which stop it. But try!

    Obviously replace strFileName with your own form name to save as, even try building it using values from your XML nodes (if you can do this, maybe can help). Also c:\ will need to be replaced with the network path - I have only ever used local drive paths - maybe network paths won't work O_O.

    good luck!

  • 11-16-2010 11:53 AM In reply to

    Re: SAVE form using button control

    I just wanted to say "Thanks" this was a great, easy piece of code to implement.  Works great!!

  • 03-20-2012 02:50 AM In reply to

    • dkanha
    • Not Ranked
    • Joined on 02-28-2012
    • Posts 4

    Re: SAVE form using button control

    Can you show the full code for save button I tryed with - Xdocument.save () But i need something more??
Page 1 of 2 (16 items) 1 2 Next >
Copyright © 2003-2012 Qdabra Software. All rights reserved.
View our Terms of Use.