Skip to main content

Notifications

Community site session details

Community site session details

Session Id : Ph+o6JPsps7Kq0HYaMyYka
Power Apps - Building Power Apps
Answered

How to handle spaces in datasource values that are utlized in URLs?

Like (0) ShareShare
ReportReport
Posted on 16 Dec 2020 22:39:03 by 634

I am building a form where the user does the following:

 

  1. Enter a base URL
  2. Chooses options from combo boxes and enters values in text boxes
  3. All of this gets entered into a datasource

Goal

Assemble these values into a valid URL.

Ex. www.website.com?utm_campaign=field1&utm_source=field2&utm_somethin=field3 

 

Now, at the moment I have each individual field getting entered into its own column in the data source. I do not assemble the URL and enter it into its own column although I am considering this. I do not account for spaces in the field values either. For example, utm_campaign might be something like "Fall Sale Event". What gets entered into the data source is "Fall Sale Event". The problem is that is you try and assemble a URL you have spaces. What should be there in place of the spaces is %20. How would I handle these spaces? Do I enter the %20 into the data being entered into each column of the data source? Do I assemble the URL and add the %20 at that point and then write the assembled URL to the data source? Or do I assemble the URL in a gallery and deal with the spaces there? And, of course, how do I handle swapping out the spaces?

 

Ultimately, this would go for any encoding that needs to be done. Not just spaces.

Categories:
  • Future_Vision Profile Picture
    634 on 22 Dec 2020 at 22:14:00
    Re: How to handle spaces in datasource values that are utlized in URLs?

    That's what I was actually noodling on doing. Doesn't even need to be hidden necessarily. 

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 21 Dec 2020 at 22:47:08
    Re: How to handle spaces in datasource values that are utlized in URLs?

    @Future_Vision 

    You could actually chain the Substitute functions if you had only a couple of conditions (i.e. Spaces and perhaps ampersands or something).  But, after that it gets just about a unwieldly.  

     

    The other thing you can do is establish a label (hidden) on the screen that has that formula in it to combine the URL with its encoding.  Then for writing the record or emailing, you can just refer to the Text property of that label.

    It will be dynamic (i.e. change based on the record) and will be readily available for where ever you need it in your app.

  • Future_Vision Profile Picture
    634 on 21 Dec 2020 at 22:36:52
    Re: How to handle spaces in datasource values that are utlized in URLs?

    Good point. I think there may be some other characters that need to be encoded but I'm not completely sure. It's probably best to capture all of them instead of just singling out spaces.

     

    As for deciding whether to pre or post encode of the URL I haven't really decided. The app is likely the only thing that is going to use the URL although I can see emails being sent as part of the process. It might be easier to just grab a single column from the data source in that case instead of trying to build the final URL on the fly. All of the 'pieces' of that final URL would still live in the data source in their own individual columns alongside the column with the fully built and encoded URL. If I go this route of building the URL before writing it to the data source is the process the same? Instead of grabbing values from the data source I am grabbing the values from each field of the form?

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 21 Dec 2020 at 22:19:54
    Re: How to handle spaces in datasource values that are utlized in URLs?

    @Future_Vision 

    Also...in reading back, you only seemed concerned with the spaces.  EncodeUrl will obviously encode the spaces and any other special characters, but if ONLY spaces are your concern, then you could consider something like this:


        Substitute(yourFinalUrl, " ", "%20")

     

    This would replace just the spaces with the "%20" needed.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 21 Dec 2020 at 22:12:56
    Re: How to handle spaces in datasource values that are utlized in URLs?

    @Future_Vision 

    Yeah, it's not optimum, but as you noted, the EncodeUrl function (if you feed it the whole url) will encode everything where you just want individual parameters encoded.  So that formula is about the best you've got.

     

    Certainly if this is a one time creation url (meaning when you are say, creating or saving a record), then I would consider creating and saving the encoded url for the future.  But if your app will be the only thing that really accesses the data, then it's just as easy to do it when selected.

    Either way works, just depends on your design.

     

     

  • Future_Vision Profile Picture
    634 on 21 Dec 2020 at 21:34:46
    Re: How to handle spaces in datasource values that are utlized in URLs?

    That could be a little unwieldy to manage especially if there are numerous parameters which could happen but I suppose it is an option.

     

    Now, I've been wondering do you encode those parameters and then write them to the datasource or do you extract the parameters from the datasource and encode them for rendering?

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 21 Dec 2020 at 19:02:13
    Re: How to handle spaces in datasource values that are utlized in URLs?

    @Future_Vision 

    Yes, I wasn't suggesting preforming the EncodeUrl function on the entire URL, only on the parameters of the URL.  

    Sorry I did not make that clear.
    i.e.

       "www.website.com?utm_campaign=" & EncodeUrl(field1) & "&utm_source=" & EncodeUrl(field2) & "&utm_somethin=" & EncodeUrl(field3)

     

  • Future_Vision Profile Picture
    634 on 21 Dec 2020 at 18:34:53
    Re: How to handle spaces in datasource values that are utlized in URLs?

    Anyone else have some ideas on ho to solve this problem? EncodeURL seems like to broad of a solution that is likely going to cause issues. I have one particular vendor that would be using these URLs that specifically says not to encode certain symbols.

  • Future_Vision Profile Picture
    634 on 17 Dec 2020 at 17:52:21
    Re: How to handle spaces in datasource values that are utlized in URLs?

    This works to a certain degree. Not all characters need to be encoded. For example I wouldn't want to encode '?', '&'; and '='. I could put an encode on every single parameter but that would be a mess. Maybe encode the values before/as they get submitted to the data source? Or is there some logic that will only EncodeURL specific characters?

     

    Perhaps a Substitute or Replace might be an option?

     

    Any ideas?

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 16 Dec 2020 at 22:59:54
    Re: How to handle spaces in datasource values that are utlized in URLs?

    @Future_Vision 

    You will want to utilize the EncodeUrl function.  This will do the conversion for you.

     

    I hope this is helpful for you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,089 Most Valuable Professional

Leaderboard