Header Ads Widget

Top Picks

6/recent/ticker-posts

Part 1 of an introduction to Business Central's custom function and user defined procedures

Multi-purpose Buttons

Introduction


One of the most fundamental ideas in computer programming is function. The first thing a developer does while writing code is to create an algorithm. This need can be satisfied in a function for easy reuse in the future.


The ability to add new functions is available in all areas of Business Central where triggers and preexisting functions are used. You are free to implement your own logic and code in these methods.


You'll study the basics of function definition and the distinction between local and global functions in this lesson.


You can use parameters to tailor the behavior of a function to specific needs. The module's focus is on teaching you how to pass parameters into a function, as well as the many kinds of parameters that can be passed in.


Why Functions?

The reason for creating custom functions is to:

  • Organize the program.
  • Create self-explaining code.
  • Simplify the development process.
  • Make code reusable, which reduces work.
  • Reduce errors.
  • Help make modifications easier.
  • Reduce the size of the objects.

A named component of a programme is a function. You can group a number of lines, give it a name, and then call this block of code by its name.


Use the tprocedure code fragment to make a new user-defined function.


local procedure MyProcedure()

begin

   // Some logic goes here.

end;


Call the function using the function name inside the object

MyProcedure()


Code snippet for a simple procedure



Code snippet to validate the age using a procedure



Save and execute the code using Ctrl+F5

The output screen looks as shown below.



Enter the value in the text box -> click Actions -> click the trigger





You can also call the procedure inside the field block. 


Please check the complete code here in the GitHub Link

Post a Comment

4 Comments

  1. Just a suggestion, we should avoid writing code in pages. Either use table or codeunit and call that function from page

    ReplyDelete
  2. Can We use that Globally instead use of local Procedure, on the current page as well as on Another page?

    ReplyDelete

Youtube Channel Image
goms tech talks Subscribe To watch more Tech Tutorials
Subscribe