Clayton's SharePoint Madness

All About SharePoint, InfoPath, and SharePoint Designer!

Auto-Generating Filenames for InfoPath Forms

Posted by Clayton Cobb on June 20, 2009


Auto-Generating Filenames for InfoPath Forms – I see this topic come up a LOT on forums all over the place, so instead of continuing to answer the question time and time again, I am going to post a quick blog entry showing the steps.  I think this stuff is fairly simple, but it just doesn’t pop into your head initially.  Once you see it and understand it, you’ll think it’s simple, too.  Keep in mind that I focus entirely on SharePoint-based InfoPath forms and for the most part BROWSER-ENABLED forms.  So, it’s possible and likely that all concepts explained here will work for non-browser forms and non-SharePoint forms, but just remember that my perspective is mostly browser-enabled.  The basis for this topic is that the standard method for submitting InfoPath browser-enabled forms is for the user to click Save at which point the user is prompted to give a filename along with choosing to allow overwrite.  I really dislike this feature, because users have no concept of proper naming convention for the most part, and there’s no way to guarantee they create a unique or meaningful filename.  I also just don’t like the user getting prompted.  I prefer for the user to just click a button that saves the file to SharePoint with a dynamically-defined filename, closes the form, and takes the user back to the forms library.  Ok, so how do we do ensure these few things:

  • The filename must be unique
  • The filename must persist through subsequent edits of the form without the user having to do anything
  • The built-in toolbar buttons must be hidden
  • A custom button must be created to do it all

Here are the steps:

  1. Create the field for storing the filename
  2. Create the Submit data connection that uses this field
  3. Disable the browser-based toolbar functions
  4. Create the custom submit button

Create a hidden field for storing filename

Create a strFilename field (Text).  Do not set any conditional formatting, rules, or data validation on this.  Add it to the canvas for now and make it read-only (Fig 1).  This will be visible for testing purposes only.

Fig 1 – Create hidden field named strFilename

Create a Submit data connection that uses the strFilename field for dynamically creating the filename

Create a SUBMIT data connection in your form template that connects to the Form Library where the form resides.  Put in the URL of your Form Library for the “Document Library” field, and choose the strFilename data element for “File name” field by using the fx button.  Check the box for “Allow overwrite if file exists” (Fig 2).

Fig 2 – Creating the Submit data connection for the Form Library

Disable toolbar options

Click Tools > Form Options > Browser.  Uncheck Save, and Save As (Fig 3).  Submit should be grayed since it has not been configured.  If it has been configured, be sure it is unchecked.  Update should be unchecked by default, so leave it.  I personally uncheck “Views,” since I use views to dynamically route people to certain information based off their identity or the form’s workflow status, but it’s up to you.  If your form is not browser-enabled, use the Open and Save menu in Form Options to uncheck Save and Save As.

Fig 3 – Disabling toolbar functions for Browser-Enabled Forms

 Create the custom Submit button

Drag a button control to your canvas and double-click it to get to its properties.  Change the display name to “Submit” or whatever you prefer, then click Rules.  You want to add two rules, each with one condition (Fig 4).

 

Fig 4 – Custom Submit button with two rules

The first rule allows you to Edit the existing form without changing strFilename, then close it (Fig 5).

  • Set a condition rule to have one condition stating that strFilename is not blank.
  • Add two actions in this order:
    • Submit to your SharePoint Library Submit data connection
    • Close

Fig 5 – Editing the form with the submit data connection

Here, we are simply submitting the form back to the library in a manner that will not change any metadata and will overwrite the existing file of the same name.  This is the whole reason for the strFilename field.  We do not want the strFilename to be recreated each time the form is edited.  This rule is placed before the Submit rule for the same reason as stated above.  We need to check first to see if the form has already been submitted.  If so, then we submit using the current strFilename.  If not, then we skip this rule.

The second rules will Submit the current form only if it is brand new and after dynamically creating the strFilename, then it closes the form.

  • Set a condition rule to have one condition stating that strFilename is blank.
  • Add three actions in this order:
    • Set the Value of strFilename (Fig 6) to the concatenated string combining userName() with now().  The formula is concat(userName(), now()).  The Xpath is concat(xdUser:get-UserName(), xdDate:Now()).  Note: I add a text hyphen in the middle to make it a little easier to read, but that’s up to your discretion.
    • Submit to your SharePoint Library Submit data connection
    • Close

Fig 6 – Setting the dynamic filename prior to submission

Here, we are submitting the form to the form library for the first time.  This is why we first dynamically create the strFilename, because the Submit data connection uses this field to create the filename in SharePoint.  We only want to do this step upon first submission, so that is why this rule only runs if the strFilename is blank.  Doing this rule last keeps us from double-submitting, because the Edit rule would run right after the Submit rule due to its condition being met (strFilename is not blank).  You can of course choose any concatenation formula you want as long as it is unique.  This particular formula can only create a non-unique filename if the same user submits two separates forms (two browser forms open simultaneously) at the same EXACT second.

Publish your form to a new form library, and set that library to Display in Browser (Advanced Settings).  Click New to create a new form (Fig 7)

FN07

 

Fig 7 – A new form before submission

Click submit, and it should take you back to the library with no prompts or delays.  You will see a new form with a unique filename (Fig 8).  The now() function gives the date AND time separate by the letter “T.”

FN08

 Fig 8 – Newly-created form has unique filename

Click on that new form and notice that the strFilename field has been populated with the same info you saw for the filename in the library (Fig 9).  This field is actually populated FIRST when you submit, because it forms the basis for the filename in the Submit data connection.  Click submit again and notice that the existing file has been changed rather than a new file being created.

FN09

Fig 9 – strFilename field is populated with the dynamic, unique filename

Reference links for related articles:

InfoPath Submit Error- A value in the form may be used to specify the file name – You may be getting this error.   This blog post helps explain why, and my blog post helps explain how to overcome it.

About these ads

171 Responses to “Auto-Generating Filenames for InfoPath Forms”

  1. sai said

    Hey Clayton,

    Nice post, this post really helped me to think and analyze what i’m doing.

  2. Hameed Bhatti said

    Excellent article Clayton!!!

  3. Hameed Bhatti said

    Clayton has been extremely helpful in helping me resolve the issue I ran into regarding saving an InfoPath form so that it does not overwrite itself.

    Not only was he prompt (and he didn’t have to be prompt – after all I was not paying him for his help), he was curteous, had great suggestions and the issue I was running into is not only solved, but he educated me about InfoPath in general and SharePoint.

    I am extremely greatful to you Clayton and I hope to learn more about InfoPath and SharePoint integration in the future.

    What book do you recommend for learning InfoPath the right way?

    Regards,
    Hameed

    • Clayton Cobb said

      Hameed, those are very kind words. Most don’t take the time to show thanks. The book that got me really going with InfoPath was Pro InfoPath 2007 by Philo Janus. It’s an easy, quick read that has examples/exercises that really help with understanding the product. I did not evaluate the coding sections, but he has some of that in there, too. I have not yet found another InfoPath book that I like, so if I find another, I’ll let you know, or maybe I’ll write my own! =)

      • Hameed Bhatti said

        Thanks for the book suggestion Clayton.

        On another note though, based on the article above, if you wrote a book on InfoPath it would be a great book too!

        Keep up the good work!

  4. Jeremy said

    Clayton, you are a true master! Thank you ver much for this blog. It’s just amazing that something so simple can go unseen. I’ve been mulling over this concept for such a long time, and yet, you’ve provided an elegant and EXTREMELY simple solution.

    Thank you.

  5. [...] another good post on this subject can be found here: http://claytoncobb.wordpress.com/2009/06/20/auto-generating-filenames-for-infopath-forms/ Possibly related posts: (automatically generated)Increasing Session Time Outs for Long Browser [...]

  6. Dave Barnes said

    Hi Clayton, This is the first post i have ever replied to. I thought would though, I found it so helpful, and has saved so much time. A big thank you, and if you ever write the book, it will be on my list of purchases. Thanks again.

  7. Bharath said

    Clayton,

    Just a quick question, I need to populate the fields i.e., i want to publish my form to a doc lib how do i auto generate and populate those fields as meta data to the form in the doc lib. Let me know
    thanks

    • Clayton Cobb said

      Bharath, you get your fields into the SharePoint form library by promoting them during the publishing process. You should see a separate screen during the publishing wizard that asks which fields you want to show in SharePoint. Whatever you add here will show up in the form library as a column that you can use for views.

      • Bharath said

        I got you. But my question is can they both be done in the same document library.. that is on the click of the button i should have the file with the field related from the file as its meta datas.

  8. Clayton Cobb said

    I don’t know what “they” are. I didn’t see you mention two things – only one. When you promote your IP fields to SP, they become columns in the form library. Columns ARE metadata that is associated with your form.

    What do you mean by “on the click of the button i should have the file with the field related from the file as its meta datas”? I don’t understand that statement. Let’s converse over email until I figure out what you mean, and then I can write the answer here for others.

    • Bharath said

      I found my mistake actually my bad.. I published the form to another library and the data connection was in a different library..Moment of Madness. Sorry for bothering

  9. Luis Felipe Carvalho said

    Great post! Really helpful! Thank you!

  10. Mark Bowman said

    Hi Clayton,

    Just letting you know that I really appreciate your posts in regard to Infopath forms and Sharepoint. I’m a Sys Admin at a medium size company, and I’m trying to reduce our paper based forms.

    Reading this post, and the “Getting user information without code” – especially the part regarding pulling Manager information from AD, is the most helpful information I’ve found so far on the Internet about this topic.

    Love your work, keep it up.

    Mark (happy admin)

  11. Steve said

    I created the submit button just as you have written above except: on the submit rule, I have concat(“Request”,numID). When the form is submitted, the form name is just the ID number. I tried to set another field to Request then concat that field with numID and still I just get the ID as the name. I tried setting the request text field to “Request” and concat(Requesttextbox,numID) and still get just the ID as name. this is not a browser ready form.
    Thanks
    Steve

    • Clayton Cobb said

      I would have to see your exact syntax within the XSN to figure that out. Every scenario you mentioned should have worked.

    • Steve said

      I have a work around in the meantime. I added Concat(“Request”,strName) to the filename in my submit data connection. Still bothers me that the concat in the rule is not working. Also, I couldn’t see your screen shots from work, they were blocked.

      • Clayton Cobb said

        You shouldn’t do that concat in the submit data connection. It should be done in the submit button rules before the submit data connection fires. The submit data connection should only be set to submit the filename as strFilename, and strFilename is populated by the concat statement in a previous rule. That field only gets populated once. The concat does work, so if you send your XSN to my email, I could figure it out.

      • Steve said

        sent the XSN to your gmail account

        Thanks

      • Clayton Cobb said

        You have a million data connections to your live site, so I can’t preview it for testing, but what I see is that you have _2_ separate submit data connections, which is a mistake. You shouldn’t be using the built-in Submit functionality but rather the submit data connection that you created by hand. You have both in there doing different things, and you have two buttons that each use a different submit technique. The button labeled “button” has the proper rules from my blog for Auto-Numbering, and it sets the strFilename to concat(userName(), numID). That’s how my stuff works, but you have been talking about some completely different filename concatenation string, which seems to be related to your other submit button (the incorrect one). What happens when you use the button from my blog?

      • Steve said

        I was trying different submit buttons. I changed my concat back to using the username() to see if that would work and it wouldn’t. I got the same thing (just the ID for the name). This has been a learning form for me. So, some of those connections could be cleaned up. The “submit” button can be deleted. I am using the one that is still called button.

      • Clayton Cobb said

        Got it. I can see no reason for your statements not to work. It makes no sense for you to have a concat statement that only displays half of the statement.

  12. Bryan Smith said

    I read through your instructions several times. I am stuck. I think you may have not included some steps since many of your readers may have more training with this than I do. I have an Infopath 03 form that I need to host on our Sharepoint 07 site. The form is already there but I have it there only in beta form for testing. The form is rather complex since it is used to track our travel around the world. I would like to do what you describe above but I get stuck around figure 5 and 6. Did you stick a bunch of rules/creations together or am I just stupid? I taught myself sharepoint and infopath but for some reason the above description is holding me up. Can infopath 2003 forms work in the way you described above with SP 07?

  13. Alex said

    Hey Clayton, Thanks for this great post. As a beginner this has helped me a lot. One thing that is puzzling me is that whenever I edit an already submitted form using “Edit in browser” and click submit, it always add a new item to the document library rather than updating the existing item. Is this how it is suppose to behave? Or am I doing something wrong here.

    Thanks.

    • Clayton Cobb said

      Did you configure your submit button the same way I show in my blog posts? If you dynamically generate your filename every time you submit, then it will always create a new filename, which in turn makes it a new file. To make sure it updates the same file each time, you need to ensure that it’s submitting the same filename as the current file and overwriting the existing file by generating the filename ONLY ONCE (on first submit) and then ensuring that your submit data connection allows overwrite. This requires having two rules in your submit button – one that fires when new and one that fires when editing. The new rule generates the filename, puts it into a hidden field, and then submits while leveraging the filename in that hidden field. The editing rule only submits and does not generate a filename, but rather uses what was saved in the hidden filename field from the original submit.

      -Clay

      • Alex said

        Clayton,

        Awesome!! saved my day. Thanks for taking your time to post this blog and answering my question in detail.

        -Alex.

  14. Munira said

    Hey Clayton, Thanks for this great post. I tried it and it’s working but in filename function I would like to replace now() with another unique field e.g. any ID (if exist) or a way of creating an incrementing counter in order to shorten the file name. Please help me with a function that is not using now()as I tried different ways but still the counter is not working. Thanks.

    • Clayton Cobb said

      Munira, thanks for the comments. You can use any other information you want for the auto-generated filename. I use the now() function with the username, because it ensures uniqueness to a probability level that I can accept. I don’t care how my filenames look, because I don’t display them. I display a form name or form title based off other information in the form, because my filenames are not aesthetically pleasing. I recommend not trying to do an auto-incrementing number in your filename just to shorten it, because you will increase complexity without gaining anything. The reason for this is because the XML files themselves are not aware of each other. In order to incorporate an auto-incrementing ID into your filename, it means your form must be aware of the next ID # before the form is ever submitted. This requires reading data from the form library, and I have a blog entry for doing that, but it has holes that you should be aware of (be sure to read the red warnings at the bottom). Here is the name: InfoPath – Auto-Numbering Forms. You can see it listed right there on my home page. SharePoint automatically assigns a unique, auto-incremented ID to each form, but that ID does not get created until the form is submitted, which means your filename exists before the ID. That’s a chicken before the egg problem, which is why I wrote the above article. However, like I said, it is not perfect and has its flaws. I recommend avoiding all of this by using a simply filename formula that you can ENSURE will always be unique.

      -Clay

  15. Alex said

    Clayton,

    Quick question, every time I edit and item using the form and click submit (when the Edit Rule is applied) I get “Form has been closed”. The form does not close properly and does not take the users back to the Document/Form Library. When I submit a new item (when the Submit Rule is applied) users dont get this message and get redirected to the appropriate library. Is this a known issue or am I doing something wrong here?

    Thanks once again for your help.

    – Alex.

    • Clayton Cobb said

      Alex,

      Something must be wrong, because I haven’t encountered that before, but I’m not sure if it’s the form, your SharePoint environment, or the method in which you are taking users to the form. Does this happen when simply clicking on an existing document and re-submitting? Is it a browser form?

      -Clay

      • Alex said

        Clayton,

        Thanks for your quick reply. Yes it is a browser form and it happens even if I simply click on an existing form and re-submit without making any changes.

        Thanks,
        – Alex.

      • Clayton Cobb said

        What do you see in the source parameter of the URL when an existing form is opened? It’s whatever you see after &Source=

        -Clay

      • Alex said

        I don’t see any “&Source=” in the URL.

        -Alex.

      • Clayton Cobb said

        And that’s why I asked – the Source attribute is what tells the browser where to send the user. If it’s not there, then the browser just says the form is closed, because it doesn’t know what URL to go to. How are you opening existing forms? What method are you using? Are you selecting “edit in browser” by chance?

        -Clay

      • Alex said

        Oh..

        Yes, I’m using “edit in browser”

        Thanks,
        Alex.

      • Clayton Cobb said

        That’s the problem – don’t use that. Is there a reason you’re using that instead of just clicking on the filename or clicking on the Type icon? Edit in Browser from the context menu does not populate the Source attribute for some strange reason (no idea why it doesn’t work right).

        -Clay

      • Alex said

        Clay, If this is the issue then I’ll get used to clicking on the Type icon or the filename and refrain from using “Edit in browser”.

        Thanks for your quick response once again.

        While searching for a solution for this I came across lots of InfoPath blogs where you have offered your help and advise free. You are a top man.

        – Alex.

      • Clayton Cobb said

        Alex, thanks for your appreciation and recognition of my efforts. Please let me know if this was in fact the issue (re: Edit in Browser).

        -Clay

      • Alex said

        Yes Clay, you nailed it. “Edit in browser” was the exact issue. When I edit the form using the type icon or the filename the form closes fine and redirects me to the library where I opened it from.

        Thanks,
        – Alex.

  16. Justin said

    Hey Clayton –

    Thanks a lot for this information, you rock!

    I’m having a little trouble with the auto generating filename getting saved to the library. When the form comes up and a user hits submit it saves as “strFilename”. When I open the saved form it does show the filename in the fieldbox next to the Submit button but never saves to the library as that name.

    Is this something you have seen before? What information can I provide you to maybe help me along? :) Thanks in advance!

    • Clayton Cobb said

      Did you actually reference the strFilename field using the function builder, or did you just type it in?

      -Clay

      • Justin said

        That was the problem! I ended up going into my data connection for submit and inserting the field rather than typing it in! Thank you so much again. Working great.

  17. Steve said

    Clay,
    I am getting the “The file is in use by another application or user.” error, but not all the time. When I reopen a form and make updates, click the save button, the saving msgbox is displayed, then the infopath error box stating some rules were not applied
    is displayed. Click OK, form doesnt close. I then click my close button. Reopen the form and my changes were updated. I have the same rules,same order on my submit button as stated in the article. Do have any ideas where I can look for the lock? thanks steve

    • Clayton Cobb said

      You mentioned saving, but I only use submitting. When you use the Save button in the toolbar, it will actually commit the save even if there are errors with validation or rules. My method that uses submit and disables the Save button will not allow the submit action is there is a problem. If you get the error that a rule was not applied, then there is an error in your syntax or logic somewhere with the button rules. I know you said you have the same rules in the same order, but there has to be a mistake somewhere. I can probably figure it out if I see the template (XSN).

  18. Steve said

    Clayton,
    I want to print my form before I submit, how can I display the filename in the form? or how can I display the filename in the form when I reopen the submitted form so it can be printed.
    Thank you

    • Steve said

      ok, nevermind about after. I just display the strname text box.

      • Clayton Cobb said

        Steve, are you all good then? That’s what I was going to suggest, since it’s the simplest answer, but I wanted to make sure you had no other questions.

        -Clay

  19. Chellie said

    Thanks for the info, it was really helpful. I’ve been working on forms for a while and each time there’s a new issue. Anywho, so I did what you did above and now I’m getting in my error message:
    “InfoPath cannot submit the form.
    An error occurred while the form was being submitted.
    The form cannot be submitted to the following location: http://sharepoint/Training/Chelle Test/Forms/AllItems.aspx/myFields2010-03-24.xml
    The folder does not exist.”

    I’m wondering if this is a rights issue? I’ve been added as ‘Full Control’ and still having some issues. The folder library has been created correctly, the submission connections are correct. I don’t know what the problem is. I’ve waste two work days on trying to fix the issue.

    • Clayton Cobb said

      Chellie, that little mistake gets people a lot. Your submit URL says:

      http://sharepoint/Training/Chelle Test/Forms/AllItems.aspx/myFields2010-03-24.xml

      It should say:

      http://sharepoint/Training/Chelle Test/myFields2010-03-24.xml

      You need to take the /Forms/Allitems.aspx out of your Submit data connection. This goes for all forms when creating submit data connections. You can’t paste in the whole URL of the All Items view (or any view). It has to be the direct URL to the form library itself.

      -Clay

      • Sandra said

        Clay Cobb your are ultimate guru! I was having the same issue each time I was setting up my options but I didn’t know why.
        THANK YOU THANK YOU THANK!!!
        I am sharing your blog with eveyone in my department! :)

        Sandra
        NYC

      • Clayton Cobb said

        Glad to help, Sandra. =)

  20. Ryan Krause said

    Hi,

    This looks like a great place for some help. I’m new to both infopath and sharepoint but know enough of the basic functionality to publish forms and link to sharepoint. What i don’t know how to do is set workflows properly. I’m looking for a little guidance with a scenario – is this something you could help with?

    Thanks,
    Ryan.

  21. Ryan Krause said

    Hi,

    I followed the instructions but it appears i’m missing an obvious step. I’m getting the coded field name (concat(userName()_ _-__ now()), instead of an actual file name. What am i missing?

    Thanks,
    Ryan.

    • Clayton Cobb said

      It doesn’t look like you truly built the function in the function builder (fx button). You can’t copy/paste the text from the blog nor can you type it into the regular field. You have to click the FX button, then build the statement.

      Also, what are those underscores? The statement should look like this: concat(userName(),”-“,now()). Maybe those characters are being converted to underscores due to how you set it up, and if so, it again points me to you possibly typing this into the Value field instead of clicking the FX button.

      • ryan said

        Yep – typing it is where i went wrong. I’ll write out the workflow and send your way for ideas on how best to do it. Thanks for your time.

        Ryan.

  22. Nersdine said

    Hi Clayton,

    Thank you! Short and efficient

  23. Colleen said

    Hi-
    This works great, but when users press “close” on a partially completed form, they are asked if they want to save the form (even thought I have Save and Save as disabled from the header). They can then save the form using any name they would like. How do I force the name to be the strfilename+date created like in your post?

    Thanks

    • Clayton Cobb said

      Disable the Close option in the toolbar, and instead, use a custom button on the form labeled Close, and have only one rule with one Close action.

  24. very clever trick for Infopath

  25. Aria said

    Hi

    Nice Post
    I spent some hour to find this!

    I submit my form in code behind , does this trick works with code behind submit() ?

    • Clayton Cobb said

      I do all of my forms without code, so I’m not sure, but I would guess that this can very easily be done through a code-based Submit.

  26. Carlos said

    Thank you very mucho Clayton! It works! you were a big help!

  27. Tommy said

    Hi Clayton

    is this for infopath 2010

    PS, nice work!

    -Tommy
    Sweden

  28. Mark said

    Great Article, Clayton! Keep up the good work!

  29. Justin Yost said

    Claton,

    Thanks for a great post!

    I am new to SharePoint and Infopath. I have InfoPath 2010 and was able to follow your instructions (I had to experiment in 2010 to find some of your steps) and I thought I was all set. However I tested my form and even though I am able to submit the form, it doesn’t show up in the library. I had already created a form, and applied your steps at the end of the form. Did that have anything to do with my error?

    Any help is greatly appreciated!

    Thanks
    Justin

    • Clayton Cobb said

      Justin, my guess is that the link you provided in the Submit Data Connection is incorrect, so the forms are being submitted to the wrong place. Your URL should look like this: http://site/NameOfLibrary/

      It should not look like this: http://site/NameOfLibrary/Forms

      Also, if it’s a meeting workspace site, then you can’t use a custom submit.

      • Justin Yost said

        So if I created a Teamsite to collect this form it won’t work?

        I am trying to collect “issues” in a site and i created a form using infopath to keep all the data the same.

        Thanks

  30. Karen said

    Hi Clayton,

    I have followed the instructions regarding overwriting a form and having a dynamic filename that never changes. My problem is if I make a change to another field on a resubmitted form and submitted it the changes are not there. I know I am missing something. Please help!

  31. Beth said

    Clayton,
    This is EXACTLY what I’ve been looking for. I’m using it in an InfoPath 2010 non-browser based form and it works great. Thanks so much.

    Beth

  32. Scott Powers said

    Clayton,

    Hate to keep bringing up this topic, but my Supply department wants me to design a Supply request form in InfoPath 2007 for them so that when it’s saved to SharePoint it will record a unique Id number in the for which will be the Job Sequence Number. They want the number like this: 0322-400, which is 0=last digit of year (2010) 322=Julian date. The final number is a sequence from 400-499 which would start back at 400 after 499 is reached. I would greatly appreciate any help you could provide.

    Thank you,
    Scott

    • Clayton Cobb said

      Scott, this should be doable except for maybe the Julian date. Where are you retrieving the Julian date currently? The rest is just concatenating alphanumeric strings. You really want to start over at 400 when 499 is reached? You will keep repeating 400-499 over and over? Getting the most recent ID in the sequence would require something similar to my Auto-Numbering blog post.

      • Scott Powers said

        Hi Clayton, Thank you for the quick response. As far as the date, they are currently placng that in by hand. And I was hoping that when we move to an automated form it could be retreived from the server when the form is saved. Is it possible to have the form convert the server date to a julian number? That might have to be something that I can work out with them as far as the date part of the sequence number. I did ask them about the 400-499 and they said that was what they are given to work with. I’m retired military and now work Government Service at a military command and this unit is only allotted requisitions within that series of numbers (400-499) then they have to start over again.

        I’m new to SharePoint and InfoPath 2007, and so are the military commands I work with. They just adopted the SharePoint System and for the most part no one knows how to do anything with it. Since I am familiar with Java and HTML I figured I would give it a shot and start building our portal to include automating routed forms with InfoPath intead of printing everything out. So I guess the big question is if it wouldn’t be possible to get the exact type of sequence number they want, maybe I could get them to use something that was similiar. The commands we work for are still routing paper and if they see that our system works, I am sure they will adopt it.

        I appreciate any help you can provide.

        Scott

      • Clayton Cobb said

        That’s strange that they’ve invested in it and have asked a non-SharePoint person to do solutions work for them. Just a very, very strange approach, but great for you in that you get to learn a very valuable skill area (very lucrative).

        I don’t know of any function out there that can provide Julian dates, but I’ve also never looked. I found an Excel formula for converting a standard date to a Julian number, and I can get the first half easily with XPath functions in InfoPath, but getting the last 3 digits of the Julian date is tough, because you can’t natively subtract dates in InfoPath. I think I can figure it out, but I can’t work on it today. I’ll blog it if I can figure it out. I basically need to subtract the date chosen from 12/31 of the previous year to determine which day of the current year we’re on, then concatenate it with the last 2 digits of the current year. I can do it all except the date subtract. I know of a formula that can subtract dates, and I use it in another form, so I’ll have to use that along with something to dynamically detect the previous year’s Dec 31st and then do the rest. The YEAR function in Excel does all this for you, but InfoPath doesn’t have an XPath formula that matches.

        If they only ever use 400-499, then that’s fine. Look at my Auto-Numbering blog to see how to use Max(@ID)+1 to do stuff like that.

  33. Scott Powers said

    Clayton, I really appreciate your help! And will see what I can do with your MAX(@ID)+1. So far I have had pretty good luck at working with SharePoint and InfoPath, but have a long way to go, as I said I have never used either until about 2 months ago. To answer your question, SharePoint has only been recently been adopted by the military and do due budget constraints, they have only a few civilian staff personnel hired who work on it, and they are not at the command I work at. As a matter of fact, they are on the opposite coast. They have mainly been maintaining the system… I got involved, because I am one of the few computer savvy people at the command and got tired of people only using sharepoint as a bulletin board/ storage for files. Plus the fact that more times then not do I hear people searching for paperwork that was routed by hand to someone for approval and no one knows where it went.

    Again Clayton I can’t say enough how much I appreciate your help!

    Scott

    • Clayton Cobb said

      Scott, you’re welcome. I wouldn’t say that “the military” only recently adopted SharePOint. It’s been at the Army and Air Force for many years. I’m a former Marine, and I have personally worked on AF systems as late as 3 years ago. I suppose it’s your particular office within a specific branch of the military. Typically, the DoD doesn’t hesitate to get proper contractors for doing advanced technical work like this. You should use every moment they give you to turn “computer savvy” into “SharePoint expert.” =D

  34. Scott Powers said

    That’s true, I should have said the echelon commander we fall under adopted just over a year ago. Your definitely right regarding the schooling, I’ve requested courses, but right now the funding is not available, so I guess they should be lucky they have me. I did talk with they supply personnel and for now I will create them an infopath template that they would have to manually Enter the JSN number in until I (with your help) can figure out a way to have it automatically generated when the filled out form is saved to SharePoint. Again, I greatly appreciate your help!

    Scott

  35. per said

    Hi Clayton!
    This is exactly what I’m trying to do but with a non-browser based form (because it’s not supported in our sharepoint version). But I can get it working, I though that ok maybe that’s because I’m using a non-browser based form, but then I saw that it worked out for Beth in the previous post above. When the new form opens in infopath and I press the submit button, the form closes but no new form is created in the form directory. I get no error messages what so ever. Any suggestions how I could solve this problem?

    Per

    • Clayton Cobb said

      The only reason my blog uses browser forms is because browser forms are harder and more restrictive. Anything I do in a browser form can also be done in the rich client. My guess is that you have your submit data connection pointing to the wrong place. It should only point to the form library and not the forms folder in the form library.

  36. Anna said

    I get this error: “Some rules were not applied.”

    I am right now creating an auto-filename for saving a web-based infopath form in SharePoint 2007.

    How can I solve this error?

    Thank you.

    • Clayton Cobb said

      By finding out what’s wrong with the rule in your submit button. Something is incorrect, which is causing one or more of the rules to fail. The error is self-explanatory, though it may not say exactly which rule. YOu’ll need to inspect the rules and find out where it broke by either removing one rule at a time or observing what all has occurred within the submit rules and what hasn’t. One test method would be to remove the “close” portion of the rules so that the form stays open, and create some temporary fields where you set their values to comments in the rule set. Basically, in your rules, you add an action for “set a field’s value” to set these fields to some meaningful value/word after each action within your rules. That way, when the button breaks, you can see which fields are populated and which are not…it’s a breakpoint.

  37. Liam said

    Hey Clayton,

    Nice article. I was wondering what you thought about enabling this functionality on a library with a couple hundred forms already in use. The most important part would be populating the strFileName var with the existing file name (i think). Is there a way to rename the existing ones? What do you think is the best approach?

    • Clayton Cobb said

      Liam, if you added this solution, then old forms would have a blank strFilename field, which means you could open each one and click “submit,” then they would be given a new filename and submitted separately from their previous name. This would create a duplicate, and you’d just need to remove the old version of each. The filename would have a date/time stamp in it that is current, so if you wanted those all to have filenames that matches their submission date, you’d need to modify this technique so that it concatenated the Created value of that form. Also, if you wanted the filename to include the username of the person who created it, you’d have to snag the Created By value and put it with Created. You’d do this for only the old ones, and then return the technique to normal for all new ones.

      This may be tedious for hundreds of forms, but I don’t know of a way to automate it for all of them, because the functionality in my blog is triggered inside the form. You could use a workflow to change all the old filenames AND to populate the strFilename so that whenever those forms are re-opened, they don’t accidentally trigger the setting of the filename, because strFilename would no longer be blank. The tricky part would be using “build dynamic string” in SharePoint Designer to mimic the concatenated filename, but that also could be done reasonably by using [CurrentItem:CreatedBy]-[CurrentItem:Created] except that CreatedBy is in the form of domain\username instead of just username. It all depends on what’s important to you.

  38. Great how-to, exactly what I was looking for – nice to include screenshots as well, thanks a bunch

  39. Nilang Shah said

    Thanks a lot for your great post, You saved my days of work !!!

    Keep up good work.

  40. zubair said

    Hi Clayton,

    Very good post, really helpful.
    I am however having an issue with saving the form to a set within a document set, Or to the right folder within a document library.(example form 1 saved in folder 1 in doc library Proposals.Form 2 saved in folder 2 in the same doc library Proposals.)

    • Clayton Cobb said

      Folders are a completely different story. You can’t variably submit to a folder without code. I don’t recommend using folders, but rather metadata, and I haven’t tested anything as part of a document set yet.

  41. Chris Dahl said

    I am using InfoPath 2010, have created the button, data connection and rules. I published the form to the site.

    When I click the “Add Document” link in the form library, I get the following error:

    *****************************************************************************************************************
    “Some rules were not applied”

    InfoPath cannot submit the form.
    An error occurred while the form was being submitted.
    One of the required values for submitting the form is missing. The value is created using the following XPath expression: my:strFilename

    If you know the value in the form that specifies this value, revise it and try again.
    **********************************************************************************************************

    I disabled both rules one at a time and both at the same time (re-published between each step) in order to test. I still get the same error.

    Do you have any thoughts on how else to test this problem?

    • Clayton Cobb said

      You get this error as soon as the form opens? What rules do you have in the Form Load rules area? It should not be trying to submit the moment it opens. Or are you saying it does this when you click Submit after opening?

    • Chris Dahl said

      Fixed it – had a typo in a rule.

      Works like a champ now.

  42. Prasath said

    Hi Clayton,

    I need to have “Save” option enabled in my form as we have a workflow associated with the library and workflow is started on form submission. Please let me know how do I have the same file name when I save and submit the form.

    • Clayton Cobb said

      Prasath, you still use submit for both your Save and Submit operations, and you still use the auto-generating filenames technique. Do NOT let your users click Save – hide it from the toolbar. Instead, you’ll create two custom buttons on the form named Save and Submit. In the Save button, your rule will first set the value of a hidden status field to “saved.” Likewise, the Submit button will set this same field’s value to “submit.” Then, both will submit using the normal submit data connection so that the filename is always the same. Then, in your workflow, add a condition in the first step that says “If Status is equal to ‘saved,’ then stop workflow.” This will ensure your workflow doesn’t execute until the form is submitted. YOu may also want to add conditional formatting to the Save button that hides it whenever the form is actually submitted unless you want people to be able to continually switch back and forth between save and submit. In my scenarios, the user usually only needs Save when initially filling out but never again after they choose to submit.

  43. Aaron said

    Clayton,
    I am very new to InfoPath and SharePoint. I need to do this same thing, but I am confused as to what comes first, adding this function into a form (that I’ve already created with InfoPath, but have not published yet) or creating the document liabrary on SharePiont.

    Thank you, Aaron

    • Clayton Cobb said

      Well, you can’t create a submit data connection without having a form library to point to, so you should at least have the form library or know what the URL is going to be before following this blog post. In general, you shouldn’t be designing a form without a publish location already, else you’re limited in many ways. Even if I create the form library through the publishing wizard of my form, I always publish right away to get the form library created and ready for all the other development that I need to do. I also publish and re-publish FREQUENTLY for testing. It’s not a good idea to do a lot of development before testing directly from SharePoint (not just Preview).

      • Aaron said

        Great!
        I got this working. Now back over to your other article about Auto Generating the ID number on my form, which is what I really am after.

        Thank you so much for your quick response (late on a Friday no less!)and not making me feel like an idiot. Your help is so appreciated. There are not many people in my company with such depth with InfoPath and SharePoint, and I tend to try to push the envelope with business process automation.

        I think your blogs are going to be my new best friend.
        Have a great weekend!

        Aaron

  44. Joanne Finn said

    I’m finding this post extremely helpful as I try to auto-generate some PO #’s on a form, but I’m having trouble seeing all the screen shots – particularly the 1st six. I’ve tried this website in 3 different browsers, checked with my IT/IS department to make sure we’re not blocking it on our end (and we’re not), but still can’t see the screen shots. Is this post somewhere else that I might have better luck viewing the screen shots?

    • Clayton Cobb said

      Joanne, it’s because those pics are all on Photobucket. I created these particular blog posts before I had a good way to embed the pictures locally. I would imagine your company is blocking access to Photobucket, because they are open to the public and others can see them fine. I need to update those blog posts with my new method, but I can’t guarantee when that will happen.

  45. Toby Studer said

    Clayton,

    First thank you for the above explanation this works beautifully. I have a new issue that I need to handle and I’m not sure how. Here’s what I have:

    I built an Action Plan using infopath 2010 and users submit the form using the same rules as above. the file name is three fields concatonated togther locName, ActionPlan title, ActionPlan Number. The problem i need help with is that after being submitted the first time the action plan title and number may get updated. but, using the above rules the file name doesn’t change. How would you suggest I handle this. I know I can create a new file with the new name but that leaves a second file with the old name sitting out there to be manually delleted.

    thanks in advance for your help,

    Toby

    • Clayton Cobb said

      Toby, if those items change, then they should not be in the filename. Why would the title and number change for an Action Plan submission? If they for sure are going to change for a given Action Plan, then don’t use them in the filename. Instead, use the techniques I show in order to ensure uniqueness and just use the ActionPlan Title and Number as metadata that you display on the form and in the view. The filename should not be something you use for purposes other than uniquely identifying your items.

      • Toby Studer said

        They change at times becuase a supervisior submits the initial form but the plant manager may want to change the title the titles are like “Roll change flour mill” and the plant manger may change to “Roll Change”. The number may mostly because we are forcing them to manually enter the number because I have not figured out a way to number these action plans. I have 40 plants using the same form in the same library and the division wants the numbering to be plant A #1 then 2 and then Plant B #1 then 2. I guess i could use SharePoint and concat those fields instead of trying to rename the file.

      • Clayton Cobb said

        You could auto-generate the numbering/naming convention for the Action Plan Number, too, but I probably can’t explain the whole thing in a blog comment. The key components would be a data connection back to the form library where you leverage metadata fields to do parameterized queries based on the plant to find out how many for a plant exist and then auto-increment the number, which would be concatenated to the Plant name and stored either in the filename or in a separate metadata field (I prefer the latter).

      • Toby Studer said

        Do you have a book or somewhere else I can get more information on how to do this?

      • Clayton Cobb said

        No, sorry. I apologize to you and everyone not yet writing a blog on this topic and many other topics. I have a million ideas and techniques in my head that I just don’t have time to write up. There is one book out there that I have in my possession, but I haven’t read it yet – the author sent it to me. It deals with building InfoPath 2010 solutions in SharePoint 2010, and I imagine it touches on these types of techniques, but I can’t verify. There is one other book that I just learned about named “*Enterprise Application Development in SharePoint 2010 Creating an End-to-End Application without Code*,” and it focuses on doing it in a codeless manner with InfoPath and SPD 2010 – it could be perfect, but I haven’t gotten my copy yet. You can find it at http://www.ihfpublishing.com .

      • Toby Studer said

        Okay I will check those books out thanks a lot. Just typing this out I have a couple ideas in my head as a solution a well. Have a great day!

  46. Doreen said

    I have used this method to autonumber forms and have added the year and username to it as well. It numbers fine except I am having problem with the filename being overwritten when next user updates the form via clicking the submit button. I have tried different combinations of checking box to not overwrite, disabling Form option for save and save as but then nothing gets saved at all.

    Ideally I would like the submit button to always save and submit to SharePoint and not overwrite the filename if it already exists. I also do not want the user to be able to save the form to anywhere but back to the SharePoint library. Can you help? Using MOSS 2007/wss 3.0 and IP 2007.

    • Clayton Cobb said

      Doreen, I don’t really understand the problem. If you used my technique, then it will only overwrite the file if the same file is edited. If it’s a new form, it can’t possibly overwrite anything if you use my technique, because the values can never be the same. If your new forms are overwriting old forms, then you didn’t set up the submit data connection properly.

      If you are saying that the 2nd user is editing the existing form, and it’s overwriting the existing form, then that is the correct behavior. Why would someone edit an existing form and not overwrite it? Do you want a new form to be created every time someone edits an existing form? That doesn’t sound good, but it can be done if you want. Save and Save As should not even be visible and are not related in this scenario – only use Submit.

      Your submit already does “save and submit” to SharePoint, but if it doesn’t overwrite the existing form, then you’re going to have a ton of forms with duplicate data. Why do you want to do that?
      The user should not even have the option to Save – that should be turned off in the Form Options. They should only be using submit, and the submit should be dynamic – no input from the user.

  47. Doreen said

    I have a submit button on my infopath form that creates a new filename if blank and does not if not blank then sends the form to SharePoint form library. This form will be used by a handful of people until its completely filled out so it is necessary for each user to be able to save and submit their changes back to SharePoint without creating a new form each time.

    I do not want them to get the message prompt to save Form1 because the form will be named for them or is already named. Therefore in the Submit button rules for Action: Close the form, I have left unchecked: If changes have not been saved prompt the user to save. No action or rule can be applied after the form is closed.

    In the data connection to submit form to library I have unchecked “Allow overwrite if file exists” to avoid the file name being written again if its not blank.

    • Clayton Cobb said

      Doreen, I’m a little confused by this one, too. You wrote two separate comments that were similar but not exactly the same. Did you intend to ask them as separate, unrelated questions, or did you accidentally post twice?

      There should be no message prompt if you are using Submit and if you followed my article. Why and when are your users getting prompted, and why is the form named Form1 if you are using an auto-generated filename? Why are you not closing the form on submit? Don’t you want it to close? I always close dynamically in my submit buttons, and there is no prompt.

      Why did you disallow overwrite if you want the file to get overwritten? This is confusing. Your first paragraph contradicted your last paragraph. You have to allow overwrite if you EVER want existing forms to be ovewritten. If it’s a new form, then there’s no worry of overwrite, because there is nothing to overwrite yet.

      • Doreen said

        I apologize for the confusion and double posting. My employer blocks and/or limits the time I can visit a blog/social site and when I clicked to post, a blocking message came back and I thought it didn’t send the first time.

        I revisited your tutorial to make sure I have set up the submit and data connections as you advised. I made some changes, now everything seems to be working.

        What I did incorrect: in the data connection to submit form to SharePoint library, I’d inserted a function to create the file name instead of using the strFilename as you directed to do. I also had the strFilename object in several areas of my Data Source when it was only needed in one section. I removed all occurances of it, then reset the strFilename everywhere it was used to make sure it was pulling from the one and only control available and it worked. FYI I am using this function to create value for strFilename:
        concat(dtmCreateDateYear, “-“, numID, “_”, userName()) where dtmCreateDateYear is a substring of the “Created” column from the SharePoint library. It parses the 1-digit year. Works great.

        Again, sorry to cause you confusion.

  48. Steve said

    Clayton,

    I have a library that has check in and check out capability. The form is only seeing the Items that have been checked in. For example, if there are 2 items checked in, the retrieveID returns id=3. However, if another user has already created an item checked out with the id of 3 and has not checked it in, I get an error (not an obvious error). I am assuming ,the form is trying to “overwrite” ID =3 but can not because id 3 is checked out. (not something I want) How do I get the retrieveID to return the correct max ID?. thank you in advance.
    Steve

    • Clayton Cobb said

      Yes, you should only ever be able to see items that are checked in. The method you’re using will only see items that are visible, so you either shouldn’t use check-in/check-out, or you’ll have to switch to a code-based method that can see the true number of items. Even so, a new item does not have an ID committed until it’s checked in the first time, because it doesn’t truly exist until it is first checked in. There is no way for InfoPath to do anything outside these bounds unless maybe if you write some nifty code.

  49. Sabina said

    Clayton rocks!
    Thank you so much. This post solved a problem for me

  50. Kim Tran said

    My name is Kim Tran. I am new to SharePoint. I created Infopath submit form, but cannot update the record. Any time I Used Edit function dropdown from sp list, it opened infopath form and when I submit it, it added a new record instead of update the current record.

    Would any one please HELP? I been tried different way for the last four weeks. My project was due last week. I am getting so frustrating SP.

    Thank you so so so much.

    • Clayton Cobb said

      Kim, that’s because your submit data connection isn’t configured properly. You need to follow my article exactly. My guess is you put your filename logic in the data connection instead of in your submit button, so it’s generating a new filename every time the form is re-submitted. My article shows exactly how to do it the right way. This is not SharePoint’s fault – this is developer error.

      • Kim Tran said

        I do not have same option under “Form Options” menu. I used MS Infopath 2003. Is it make any diffrent?

        Thank you.
        Kim

      • Clayton Cobb said

        I’m not sure – I haven’t used InfoPath 2003 since 2006. I only rarely use 2007 now (mostly 2010).

  51. Kim Tran said

    I use Sharepoint 7 and Inforpath 2003.

    Kim

  52. Sabina said

    Hello Clayton.
    I have my form in InfoPath 2007 in english, now I need to translate it to French. The problem is that validation Info and automatic message boxes (like one that appers if form can not be submitted) appera in English. How can I change it to French?

  53. Sabina said

    Clayton,thank you again. Will you be so kind and help me with raletd question.
    Lets say I dont want users to change data in the form after they submit, so I dont include the save option and have only submission. If strFilename is blank:set fields value of strFilename concat(userName(), “_”, now());submit and close the form. It works perfectly- when users open their form after submision the button is disabled because strFilename is not blank. The problem is if they forget to fill out one of the mandatory fields and press submit button, the warning message appears and form doesnt submits, but the strFilename is not blank any more. So when the user realises about his mistake and fills out all the mandatory fields he cant submit the same form bc submit button button stop working

    • Clayton Cobb said

      Sabina, yes, that’s why you must use conditional formatting to disable the submit button if some fields are not filled out. Do not let your users even make the mistake. Disable the button until they have completed everything.

      • Sabina said

        I can disable the button untill the mandatory fields are filled out, but lets say I have a fields with the Time format-military slyle and the user will fill it out in a wrong way like 1230 instead of 12:30. The field will become dashed but user will not notice it, move on and then press the button.
        Again, the warning message appears and form doesnt submits, but the strFilename is not blank any more.
        I dont think ther there an option to use conditional formatting in that case. What should i do?

        Thank you

      • Sabina said

        Oh, I can actually use conditional formatting like hide the button if the Time field doesnt match the setain pattern…
        Seems like I’ve unswered my own question. Hope all the rules will not make my form too “heavy”since I have more than 10 for one button

  54. Heather Zerfass said

    Hi Clayton,

    In a post on MSDN you had mentioned that there is a way to automatically add blank InfoPath forms in a library by using a workflow. Could you give me some resources that I could review on how to do this? We have a lot of information that we get on spreadsheets and it would be very helpful if we could copy and paste the information into a library in SHARE and have the forms automatically populated with the information. I would greatly appreciate any assistance or resources that you could provide. Thank you!

    Heather

    • Clayton Cobb said

      Here’s the trick: http://www.bizsupportonline.net/blog/2009/06/create-infopath-forms-sharepoint-designer-workflow/. You’d need to create the form template first with all the necessary fields, publish the form, promote all those fields while publishing, CHECK THE BOX TO MAKE THOSE FIELDS EDITABLE, and then use workflow to create a bunch of instances. Then, you could use datasheet view to copy/paste the data from Excel to the form library. Or, create a custom list with all the fields from Excel, configure the view to be in the exact same order as Excel, paste all the data in, then create a workflow on that list that creates one form per item and sets all the fields of the form library to the corresponding fields of the list.

      • Heather Zerfass said

        Thanks so much for this! I’ll give it a try and let you know how it goes. :)

  55. Redchez said

    Hi

    I have found this post great for creating some really useful forms in a Universtiy enviroment and it works great. The next step is to enable different users to go to different views. For example when a user fills in a form, we do not want them to be able to save it, which is easy enough. However I would then like a group of administrators to be able to make changes. I have looked into user roles, but when I add this to the form options as a switch views rule, it takes all users to that the save view.

    Under form options I have the following rules:

    User’s current role is equal to “save” switch view to save view
    Switch view to submitted (strFilename is not blank)

    It seems adding the user role rule is creating problems, as it works fine before I add this. Any ideas would be much appreicated. Thanks.

    • Clayton Cobb said

      Cheryl, the User Roles idea should work fine, so my guess is that your logic is incorrect. The way you wrote the form load rules concerns me a bit, because you started by stating your condition and then stating the action, but then on the 2nd rule you stated the action and put the condition in parentheses. Anyway, if those are 2 rules with their own conditions, then they are going to run in sequence. If the user’s role is “save,” then it will switch to the save view, but then it will continue and switch to submitted view if the file is not new. If your intent is to send administrators to a Save view on a file that has already been created, then you need to check the box that says “stop processing rules” on that first rule so that it doesn’t switch views again.

      • Redchez said

        Thanks Clayton

        I’ll give the “stop processing rules” checkbox a try. Sorry I wrote the rules in haste and they don’t reflect how they they are actually written in the form (unhelpful, I now realise :))

  56. Redchez said

    Hello again

    I’ve tried the checkbox option and it still doesn’t work. I’m sure it is something simple I’m doing wrong. I’m just not sure what.

    Under form options I have the following 2 rules:

    1. strFilename is not blank – Switch to view: submitted view
    (this is a view where the user cannot save the document)
    2. Users current role is equal to save – Switch view: save view
    (after the user has completed the form, I would like the administrators to go in and be able to edit and save the form if necessary)

    When I publish the form and open it from the SharePoint form library, the form opens in save view. I’m not one of the users named in user roles.

    Do these rules need to be in a certain order? Although I’ve tried changing them around and I still get the same result.

    Thanks
    Cheryl

    • Clayton Cobb said

      Cheryl, it can switch you to that save view unless you meet the condition, so you either have to be in the user role, or you accidentally set the save view to the default view. The rules look fine, but I have to take your word for everything, and in my experience, the form will ALWAYS do what you tell it to. So, when something doesn’t happen as you expect, it’s typically due to faulty logic. I just can’t tell what the faulty logic is based off what you’ve written.

      • Redchez said

        Hi again

        After a break from this, I came back to it and I’m getting to breaking point as I I still cannot get the switch views action to work despite many hours searching the internet. Further investigation seems to show that every user is being assigned the save user role, even though I have only added two users (myself & a colleague to the save user role). I’ve logged in on my colleagues account who weren’t assigned a role and they are also given the save user role.

        Am I being stupid? but how does InfoPath identify which user is which? I’m assuming that because I’ve chosen the users from the active directory that they would automatically be identified, but now I’m starting to doubt myself. Could this be the problem?

        I have set up my submit and save button as detailed above and these work fine, I’ve added no other code etc within the form. It just seems to be the switching views I’m having trouble with.

        Basically I have 3 views on a NON – broswer based form:

        1. Submit (the user fills in the form and submits to a SharePoint library)
        2. Submitted (the user can go back into the form but cannot re-submit or change the form)
        3. Save (I need approx 5 admins to be able to go into the users submitted form and be able to make changes and save if necessary).

        I really would appreciate anyone’s further help/suggestions on this as I’m on a farily tight deadline and would like this working before I start maternity leave.

        Thanks

      • Clayton Cobb said

        Cheryl, are you using the actual User Roles feature in InfoPath, or are you just using rules in your Form Load? How do you know every user is being assigned the “save user” role? What is your indication? Do you have more than one User Role defined? If so, then be aware that user roles go in order and get really hairy when people belong to more than one user role. Also, it’s very common to mess up the Form Load rules for switching views, because the rules run in order top to bottom, so it’s easy to mix up the logic.

  57. Tex said

    We are using SharePoint 2010 and InfoPath 2010. I’ve created a form in InfoPath 2010 called “Pre-Termination Advice”. When the submit button is clicked, it submits to a SharePoint library and given a unique name. What i also want it to do is after it is submitted to SharePoint, an email is sent to a person (or a group of persons) with the link to the newly created form in SharePoint, that’s all. I don’t want the form to be displayed in the email, just the link is good enough. I’ve spent weeks on this and still unable to figure this out. It may have something to do with creating a workflow in SPD but i don’t know how. Any help would be much appreciated.

    • Clayton Cobb said

      What did you try doing when you spent weeks on it, and what was the result? Yes, you would create a workflow in SPD that sends an email with a link to the form.

  58. Tex said

    Spent most of the time googling, trying to find an article to do this. I’ve tried creating a rule to submit email in Infopath but it doesn’t work the way i want it. Then tried to create a workflow in SPD but got confused on how it links to my form. I only just started working with SP, SPD & Infopath in recent weeks so these are all very new to me.

    If you could show me how to create the workflow in SPD that sends an email with the link to the form, i’d appreciate it very much. My form is working fine submitting to SP and creates a new unique name each time based on your instructions at the top.

    • Clayton Cobb said

      You just use a “send email” activity and put the link in the body of the email. Use “add lookup to body” and select “Encoded Absolute URL.” See how that works for you.

      • Tex said

        You are an absolute genius Clayton!!! what you suggested works an absolute treat. Can’t believe it’s so simple and yet took me so long to research and many sleepless nights. Just couple more minor things though

        1. The email works and the link is in the body. When user clicks on it, it needs to be in read-only mode. They can only view in the browser but can not make any changes.

        2. When viewing the form in the browser, i need to submit button to be hidden. Currently it’s still showing.

        Thanks in advance.

      • Clayton Cobb said

        Tex, those two requirements both need to be done inside the form itself. The link can’t control those things. You have to add logic to your form that tells it when to switch to a read-only view, and that view should not have the submit button on it.

        Everything in InfoPath is just logic. It won’t show read-only and won’t hide a button unless you tell it to, so you need to start telling it. Somehow, the form needs to know under what condition the form should be opened read-only. I have blog posts for that, too (user roles in browser forms).

        Also, if this is supposed to be a browser form, then the workflow hyperlink is going to need to be changed to a Forms Services URL so that it automatically opens in the browser when clicked. I have answered that question about 100 times on the MSDN forums, so I recommend finding my examples and trying them.

  59. Jasper said

    I have a solution:

    I had previously got to the stage you describe in your steps, and was pleased to find that I wasnt alone. I found the discussion here very helpful and appreciate the time you’ve taken to reply to everyone.
    I have a form that has multiple views and follows a linear progression of digital signatures, using Nintex Workflow to fire off emails to the sigs required etc.
    Here’s what I do:

    Tied to the submit button is an SQL query that returns a counter variable from the table, adds 1 and stores it in a variable which I use to make a concat. file name.
    The very first thing I do in the workflow is add 1 to the database entry with a SQL statement.

    This gets around the Sharepoint ID catch 22 and means that the first file you create in the list can begin at any number you want. The robustness might not stand up for a torrent of forms being submitted, but I have tested it several times with two forms being submitted at the same instant several times with a colleague and it holds.

    Hope this helps someone!

  60. John Gentile said

    Clayton, I used this method for a very complex set up and it worked great. I’ve created a master form library that our quality manager will use, and 8 other form libs for our 8 divisions. When someone submits a form, it goes to the master and also to the division’s lib. The quality manager sees all the forms, and each division manager can look at just their forms. And if they have to edit a form, it saves it without creating a new file.
    Thanks for the info.

  61. Tex said

    Hi Clayton, i followed Itaysk’s intructions to use the GetUserProfileByName and managed to retrieved the logged in user’s first and last name ok. However it only works in InfoPath 2010 with Preview. After i’ve published it in SharePoint 2010 and test the form, the fields are blank. My colleague here has a similar form with the same fields – First and Last name. it works fine in SharePoint2010. This is what we both have for the First Name field “xdXDocument:GetDOM(“GetUserProfileByName”)/dfs:myFields/dfs:dataFields/tns:GetUserProfileByNameResponse/tns:GetUserProfileByNameResult/tns:PropertyData[tns:Name = "FirstName"]/tns:Values/tns:ValueData/tns:Value”. Just can’t understand why his published form works in SharePoint 2010 and mine doesn’t. We both publish to the same server – site.
    Your comments (or anyone) would be much appreciated.

  62. Scott said

    I have designed a form in InfoPath 2007 with a submit button and multiple views that change based on the workflow status in SharePoint 2007 library. When the form is filled out and submitted to SharePoint via the form button the form submits, posts and enters workflow properly. However when you open the form up again the link to the secondary data source to show the SharePoint work flow status will not retrieve and all attempt to force a refresh are unsuccessful.

    Now if you take the same form and use the Save icon on the tool bar, the form will save and post properly to the library. Then when you open the form again the workflow status appears and the screen view changes just the way it is suppose to. As such I have come to the conclusion after much testing and research that when you use the built in InfoPath submit function to create unique file names, is somehow disabling the form’s retrieving process and nothing I seem to do changes this. I know that it will work because it work properly with the save icon. So my question is has anyone seen anything like this and how do I fix. Thanks in advance.

    • Clayton Cobb said

      Using Submit definitely does not affect the query process with data connections. I never use Save and only use custom Submit buttons and have not ever run into such a limitation. My guess is that it’s related to the method by which you’re retrieving that data and associating it with the current form.

      • Scott said

        Any ideas? I am at a loss. The will retrieve properly if you just save the file. But as soon as you use the submit button the form will submit and post with all of the promoted fields but will not retrieve the data.

        I also tried a custom button for both submitting and refreshing with rules and it just will not retrieve.

        Do you think it could it have something to do with SharePoint patches, security or someother back end setting.

      • Clayton Cobb said

        Please thoroughly explain the statement of “it will not retrieve.” What exactly does your data connection do and how are you confirming that it returns no information?

  63. Scott said

    I am trying to pick up the SharePoint workflow status so that I can flip the screen views in the form. If you just save the form and name it yourself the status come back correctly and the screen change. If you use a submit button, or a refresh button, the form posts properly with the dyamic name and all of the promoted fields land properly, but the SharePoint data for workflow will not come back to the form. So when you open the form again it is the same view.

    I have tried everything I can thing of and it will just not response

  64. Scott said

    Also I put the secondary data source fields (ie. workflow status, modified by etc.) in the form so that I could see what values it returned when it querried SharePoint. That plus the screen changes is how I know it is not responding. Do you thing there maybe a system problem, because I agree with you this should not be happening.

  65. Tex said

    Hi Clayton, regarding my previous post, i’ve managed to get the first and last names working in SharePoint 2010 by re-doing the form again from scratch using a blank form. The fields work by loading the current user every time the form is opened which is fine. However as this form will be viewed by everyone in the organization, i’d like these fields (First and Last Names) to stay with its original creater once filled out and saved and not loading the current user every time it’s opened again. I’m thinking of creating 2 separate views, one for managers and one for normal users. The normal user one will be read only and should show the original creater of the form NOT the current user when opened. Can you show me a way around this? Thanks.

    • Clayton Cobb said

      Tex, I actually do both in every form. You should have a group of fields for your Submitter and another group for your Current User. You set the Submitter fields by using default values, which will only populate the first time the form is used. For Current User, you use Form Load rules that physically push the data into those fields when the form opens. These techniques are shown in my other blog on User profile properties.

  66. Gaurav Goyal said

    Hi Clayton,

    I wanted to know that without code how can I check errors or any validation messages. I have a form and on this form I have 15 mandatory fields and then I have a flag button called Proceed. Button should be disabled if any mandatory field is not filled. If all mandatory fields are filled then Proceed button should work.
    Is there any function or way for infopath to check this?

    • Clayton Cobb said

      You just have to add a formatting rule to your Proceed button that says “If Field1 is blank or if Field2 is blank or if Field3 is blank…..then disable this control.” Do this for all of your mandatory fields, and the Proceed button will be disabled until all of them have data. There is no built-in function to automatically detect this.

  67. sid said

    Hi Clayton,

    Works like a charm only for the first time though. The subsequent submit only puts in a ID number.

    Any idea what could be wrong here?

  68. Steven Barrett said

    This post clearly provides the solution to how to auto-generate filenames but I’m still at a loss on how to deploy this to a reuseable form (based on a content type). I’d like to use a single form throughout a site collection but as soon as the form is modified to use a data connection, it become tied to a particular destination.

    I suspect that there is another thread out there about relative URLs and multiple data connection libraries in sub-sites but I just can’t find it.

    • Clayton Cobb said

      Unfortunately, there is no story for relative connections. You just have to get good at quickly modifying the manifest.xsf quickly in Notepad whenever you move the form around. There is no solution for massive, automated re-use without code or full backup/restore.

      • Steven Barrett said

        I see. Well, better to know the hard facts now rather than continue an aimless search.

        Thanks for the response.

  69. With Office 365 this does not work. You get the following errors when you try to use GetUserProfileByName. DOe sanyone know how to get around this?

    An error occured querying a data source.
    Click OK to resume filling out the form. You may want to check your form data for errors.

    Error Details:
    An error occurred while trying to connect to a Web service.
    An entry has been added to the Windows event log of the server.

    Log ID:5566
    Correlation ID:feb8b1f7-2a35-4e11-8d79-ba5b268b6ce6

    • Clayton Cobb said

      I have not figured out a workaround and have complained about this problem since O365 first went live. The product team is aware but will not/cannot make the necessary adjustments to the environment for allowing the browser to make data calls back to the SharePoint site. It is very disappointing…

  70. Hi Clayton,

    Thanks so much for this article! I am in the process of taking one of my clients from all paper-based processes to virtually paperless. Needless to say that is being met with some resistance from those that are used to the older ways. Anything that makes the process easier for the end-user such as auto-generating a filename so they don’t have to do it only helps ease some of their apprehension. You also have a Youtube video on a time-off request solution through SharePoint that automatically deducts time and notifies the user if they don’t have enough time. Have you packaged that for sale, or is there any other way I can get more information on that? Thanks again and I hope you keep posting this great information for enthusiasts like myself.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 173 other followers

%d bloggers like this: