Announcements
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
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!
Cannot implicitly convert type 'Text' to 'Char'
ParamsSeparator := '%26'; // URL-encoded ampersand
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156