web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / My NAV Notes / How to create functions (pr...

How to create functions (procedures in AL)

Community Member Profile Picture Community Member

In this post some examples of how to accomplish things in AL. I’m sharing this because it saves me time if I don’t know anymore how to do certain things.

  • A simple global function
  • A simple local function
  • Global function with OnPrem scope attribute
  • Global function with Cloud scope attribute
  • Local function with parameter list and return value

Simple global function:

procedure GlobalFunction()
var
    Int: Integer;
begin
    Int := 1+1;
    Message(Format(Int));
end;

Simple local function:

local procedure LocalFunction()
var
    Int: Integer;
begin
    Int := 1+2;
    Message(Format(Int));
end;

By default global functions in codeunits for example are available as methods in webservices if the codeunit is published as a webservice. By using the scope attribute a function can still be Public without being available as a webservice method;

  • Global function not available as webservice method
  • Global function available as webservice method

Global function not available as webservice method

[Scope('OnPrem')]
procedure GlobalFunction()
var
    Int: Integer;
begin
    Int := 1+3;
    Message(Format(Int));
end;

Global function available as webservice method: see the default global function. Global functions are by default a webservice method when the object is exposed as a webservice. The scope attribute is by default ‘Cloud’. So specifying is not neccesary:

[Scope('Cloud')]
procedure GlobalFunction()
var
    Int: Integer;
begin
    Int := 1+4;
    Message(Format(Int));
end;

Local function with parameter list and return value could look like this for example:

local procedure SumFunction (x:integer;y:integer) "SumResult" : integer
begin
    Exit(x+y);
end;

This was originally posted here.

Comments

*This post is locked for comments