locked
Get Infopath file name through coding RRS feed

  • Question

  • Hi All,

    I have an infopath form with a button and i published this form to a form library.

    When some one opens this form and click on this button, I need to fetch the name of the current file which is already saved in a form library.

    How can I achive this through coding/programmatically (onclick event of the button). I am using Infopath 2007.

    Thanks

    Friday, July 29, 2011 10:20 AM

Answers

  • How is the name being set?  Is the user choosing the name?  If the user is choosing the name, that's not a good because another user could come in and choose the same name and overwrite the existing file.

    What I do is autogenerate the name using the ID from the forms library itself.  Clayton Cobb has written a great post for that

    Basically, you set the filename on submit (or you can do it on open - but then you'd need to add a rule to save it right away), store the filename in the form by adding a field called "formName", or something to that effect.  Then you just keep reusing the "formName" field as your form's name on every submit.

    Friday, July 29, 2011 1:02 PM
  • You have to think about this - Adding Managed Code would make the Form Template to be Admin Approved, which has to published through CA.

    Do you really wish to add code to the form, when you can achieve the functionality you mentioned above, through No-Code solutions?

     

    As Melissa mentioned, there has to be a unique name for each form in the Forms Library, to avoid overwriting issues.

    Clayton's posts are extremely well written and can be trusted at any point of the day.

    If you are looking for something very simple, user readable and which can aid in BI later on - Do something like this:

    1. Create  a new field called "formName" - Which will contain the name/title of the form

    2. On Submit to the Form Library, Add a rule to set a field name - Set "formName" as concat(formName + "-" + now()). [The function now() gives you the current date and time]

    3. If you are looking for more precision, you could even add the currentuser filling out the form to the above mentioned filename.

    4. Now you can set up rules on a button to set a field value to this formName.

    Simple enough, right? 

    As mentioned these are all - No code solutions to get a unique filename - It is YOU who has to make a decision, if you want to add code and the overhead to go to your admin everytime this Form Template has to be deployed.

     

    Hope this helps.

     

     

    Friday, July 29, 2011 3:10 PM

All replies

  • How is the name being set?  Is the user choosing the name?  If the user is choosing the name, that's not a good because another user could come in and choose the same name and overwrite the existing file.

    What I do is autogenerate the name using the ID from the forms library itself.  Clayton Cobb has written a great post for that

    Basically, you set the filename on submit (or you can do it on open - but then you'd need to add a rule to save it right away), store the filename in the form by adding a field called "formName", or something to that effect.  Then you just keep reusing the "formName" field as your form's name on every submit.

    Friday, July 29, 2011 1:02 PM
  • You have to think about this - Adding Managed Code would make the Form Template to be Admin Approved, which has to published through CA.

    Do you really wish to add code to the form, when you can achieve the functionality you mentioned above, through No-Code solutions?

     

    As Melissa mentioned, there has to be a unique name for each form in the Forms Library, to avoid overwriting issues.

    Clayton's posts are extremely well written and can be trusted at any point of the day.

    If you are looking for something very simple, user readable and which can aid in BI later on - Do something like this:

    1. Create  a new field called "formName" - Which will contain the name/title of the form

    2. On Submit to the Form Library, Add a rule to set a field name - Set "formName" as concat(formName + "-" + now()). [The function now() gives you the current date and time]

    3. If you are looking for more precision, you could even add the currentuser filling out the form to the above mentioned filename.

    4. Now you can set up rules on a button to set a field value to this formName.

    Simple enough, right? 

    As mentioned these are all - No code solutions to get a unique filename - It is YOU who has to make a decision, if you want to add code and the overhead to go to your admin everytime this Form Template has to be deployed.

     

    Hope this helps.

     

     

    Friday, July 29, 2011 3:10 PM