Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Issue with Ampersand (&) Not Appearing when Concatenating

(1) ShareShare
ReportReport
Posted on by 16

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!

  • Suggested answer
    Khushbu Rajvi. Profile Picture
    17,402 Super User 2025 Season 1 on at
  • Verified answer
    Mohammad Usman Sajid Profile Picture
    2 on at
    Issue with Ampersand (&) Not Appearing when Concatenating
    Hi, after trying out many different things.

    Just found this out:
     
    ParamsSeparator := '&&';
  • Gerardo Rentería García Profile Picture
    19,937 Most Valuable Professional on at
  • CU-13072004-0 Profile Picture
    16 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.
  • Vahid Ghafarpour Profile Picture
    11,787 Super User 2025 Season 1 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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 1,452

#2
YUN ZHU Profile Picture

YUN ZHU 1,313 Super User 2025 Season 1

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 1,083 Most Valuable Professional

Featured topics

Product updates

Dynamics 365 release plans