VS Code Fix Variable Name Upper/Lower case

jordi79jordi79 Member Posts: 275
Hi,
Dynamics BC variable names are not case sensitive.

E.g. you can declare a variable with name of "PurchLine", and you can refer to this variable when coding with "pUrChLiNe".
e.g.
              field("Date Filter"; DateFilter)
              {
                  ApplicationArea = All;
                  Description = 'Specify Date Filter';
                  trigger OnValidate()
                  var
>>                    DateRec: record "Date";
                  begin
>>                    daterec.setfilter("Period Start", DateFilter);
                      datefilter := daterec.getfilter("Period Start");
                  end;

              }

DateRec in snippet above is not in correct case, but VS Code still accepts this. But is there anyway for VS Code to autofix the variable names? so that the case is as per what is declared in the variable?

I know it's probably not important as the code compiles and runs anyway, but my inner OCD is bugging me.

Best Answer

  • DenSterDenSter Member Posts: 8,307
    edited 2021-08-22 Answer ✓
    There is a VSCode extension that fixes the casing of AL keywords, the "AL Variable Helper", see screenshot. So if you convert some code from C/AL you'll see a lot of SETFILTER and FIND and such, those can be fixed by the extension. It didn't always work properly but that's probably because I wasn't using it right, but it's helpful nonetheless
    6izjs2tx6ztf.png

Answers

  • DenSterDenSter Member Posts: 8,307
    You can put your cursor at the end of the variable name and invoke intellisense, it'll drop down the variable name and replace it. No way that I know of, other than Find/Replace, to do it at scale.

    Dirty trick could be to do F2 on the variable name, change it to something else and then back to the proper case. Copy DateRec to clipboard, F2 and change it to 'dummy', F2 and paste DateRec, should be fixed.

    To satisfy your OCD, you should develop a habit of never typing in the wrong case. Use IntelliSense. In this function you could type 'dr' and that should dropdown IntelliSense and then you can pick the right variable name.
  • DenSterDenSter Member Posts: 8,307
    edited 2021-08-22 Answer ✓
    There is a VSCode extension that fixes the casing of AL keywords, the "AL Variable Helper", see screenshot. So if you convert some code from C/AL you'll see a lot of SETFILTER and FIND and such, those can be fixed by the extension. It didn't always work properly but that's probably because I wasn't using it right, but it's helpful nonetheless
    6izjs2tx6ztf.png
  • jordi79jordi79 Member Posts: 275
    Thanks a bunch.
Sign In or Register to comment.