Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Unanswered

Issue with Ampersand (&) Not Appearing when Concatenating

Posted on by 8

Hi everyone,

I’m working on a project in AL where I need to build a URL with query parameters. Everything works fine when I use other characters as the parameter separator (like #), but when I use the ampersand (&), it doesn't show up in the final URL string. Here’s the relevant portion of my code:

procedure GetUriWithQueryParams(BaseUri: Text; QueryParams: Dictionary of [Text, Text]) FullUri: Text
    var
        DictionaryKey: Text;
        ParamsSeparator: Char;
    begin
        ParamsSeparator := '&';
        FullUri := '';
        FullUri := FullUri + BaseUri + '?';

        foreach DictionaryKey in QueryParams.Keys() do
            FullUri := FullUri + DictionaryKey + '=' + QueryParams.Get(DictionaryKey) + ParamsSeparator;

        FullUri := FullUri.Substring(1, StrLen(FullUri) - 1);
    end;

When I test the function, the & separators don’t appear between the query parameters in the final URL, but if I change the ParamsSeparator to something else (like #), the URL is built correctly with that separator.

For example, calling the function with this input:

dict1.Add('key', 'daskdkakdakda');
dict1.Add('someVal', '123412314');
dict1.add('third', 'sdakda');
Message(GetUriWithQueryParams('http://api.weatherapi.com/v1/current.json', dict1));

Produces this result:

http://api.weatherapi.com/v1/current.json?key=daskdkakdakdasomeVal=123412314third=sdakda
It seems like the & symbol is just ignored.

Is there something I’m missing about how AL handles the & character in strings or URLs? Has anyone encountered this issue before or knows how to fix it?

Any help or advice would be greatly appreciated!

Thanks in advance!

  • gdrenteria Profile Picture
    gdrenteria 12,183 Most Valuable Professional on at
  • CU-13072004-0 Profile Picture
    CU-13072004-0 8 on at
    Issue with Ampersand (&) Not Appearing when Concatenating
    It doesn't work.
    It's a little dumb as it literally interprets it as the sequence {%,2,6}. Also when I try to assign this value ('%26') to a char variable, it says 
    Cannot implicitly convert type 'Text' to 'Char' 
    
     And consequently if we assign '%26' to a text variable (to fix the compiler error), so e.g. TextVar := '%26', and we write Message(TextVar), this code would produce a pop up with the message '%26', not the & symbol.
  • VaHiX Profile Picture
    VaHiX 3,053 on at
    Issue with Ampersand (&) Not Appearing when Concatenating
    I suggest trying this change:
     
            ParamsSeparator := '%26'; // URL-encoded ampersand
    
     

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans