Dynamics 365 Dynamics NAV 2017

Display CAL and C# code of a object in RTC

CAL, the language we use in Dynamics NAV objects. Most of us know that CAL is converted into C# at compile time. After this point, the CAL code doesn’t play any part. The converted C# code is then handled by DotNet Framework when we run the object and the appropriate result is displayed.

NAV save this code in table 2000000071 Object Metadata. In there you can find two blob fields User Code, and User AL Code.

User AL Code contains the C/Al code of the object whereas User Code contains the C# code of the same object which is generated when the object is compiled.

We can see both the Code Blobs in RTC. This would also allow us to see code of objects which are not in our License range.

I created a simple NAV Page to see this code in RTC. You can download it from here (Tested in Nav 2017) and use it. Follow the steps below if you want to create it on your own.

 

Steps.

  1. Create a new page in your object range
  2. Define these global variables as shown below.

  1. Then design the ‘Object’ group and ‘Code’ group as shown below.
  2. In the Code group add a new field and in the properties, Go to ‘ControlAddin’ property and add Dynamics.Nav.Client.CodeViewer;PublicKeyToken=31bf3856ad364e35 as shown below.

 

Note: This is the same control addin as used by the debugger. This provides syntax highlighting for the code.

  1. Create a new function like below.

Syntax:

LOCAL GetCode()
IF ObjectMetadata.GET(TypeOption,ObjectID) THEN BEGIN
  AllObj.GET(TypeOption,ObjectID);
  ObjectName:=AllObj."Object Name";
  IF CodeType=CodeType::CAL THEN BEGIN
    ObjectMetadata.CALCFIELDS("User AL Code");
    ObjectMetadata."User AL Code".CREATEINSTREAM(CodeStream);
  END ELSE BEGIN
    ObjectMetadata.CALCFIELDS("User Code");
    ObjectMetadata."User Code".CREATEINSTREAM(CodeStream);
  END;
  Code.READ(CodeStream);
  LineNo := 1;
  CurrPage.CodeViewer.LoadCode(Code,LineNo,BreakpointCollection,TRUE);
END 
ELSE BEGIN
  MESSAGE('Object Type "%1" and ID "%2" does not exist',TypeOption,ObjectID);
  ObjectName:='';
  CurrPage.CodeViewer.Clear;
END
  1. Create a new action and call this function it.

That’s it. The page is created.

Just select the type of object, Object ID , Code type and then go to actions and click on GetCode. You will be able to see the code of the object.

 

 

 

 

3 comments

    1. Yeah and this can also help us to check code of objects from published extensions which are not visible in Developer Enviroment.

Leave a Reply

Your email address will not be published. Required fields are marked *