Replacing Spaces with Underscores in InfoPath

InfoPath QuickTip

Problem: you want to use a text field in an InfoPath form to create the filename but you need a way to automatically remove spaces in the text string and replace with underscores.

Solution: Use the translate function.

Version: InfoPath 2010

Steps:

  1. Open your data connection that is set to submit your form. Click the fx button next to File name:

  2. Click the Insert Function box on the dialog that displays:

  3. Select Text > Translate and click OK:

  4. The following will display:

  5. Click in the first link and select the field that you are using to create your filename (here I am using Filename, which is a hidden field that uses a rule to create the fields data by adding the JobTitle field underscore the date/time field. I did this so I could create a rule that allowed users to submit the form more than once without the filename recalculating the date/time for each submit…)
  6. In the next link, type: " " quote space qoute.
  7. In the last link, type: "_" quote underscore qoute

  8. Click Ok and Finish and then save your form, publish and test. Here is what my test file looks like. I typed in Web Producer as the job title, and the Filename field was formed by adding JobTitle_date/time:

Advertisements

3 thoughts on “Replacing Spaces with Underscores in InfoPath

  1. Yes translate works for a one-to-one match eg ” ” with “_” but a common requirement is to replace ” ” with “%20”. Now this does not work because translate replaces matching string lengths so it cannot replace a single space character with the required 3 character string %20.

    Any ideas on how to do this?

      • Hi Waleed

        I got around this by using a tool called Qdabra QRules and put the code onto the submit fuction which replaced the spaces in the filename. Not ideal because someone has to edit the infopath form for it to work but it worked for me. Using QRules adds a lot of functions to your InfoPath solutions. I find it very useful.

Leave a Reply

Fill in your details below or click an icon to log in:

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