Create a class in AX using x++ code

X++ Programming Language / OOP Concepts

773

Program:

//How to create a class and access it from another Job
//Class Declaration: 
public class Class1
    {
        str firstName;
    }
  
//Method:
public void setFirstName(str _firstName)
{
        firstName = _firstName;
}
 

// Method: 
public str getFirstName()
{
        return firstName;
}
 
// Job: 
/*
We will access our class using this below JOB
Class1 is present in the class section
*/

public static void runYourOwnClass(Args _args)
{
        Class1 c1;
        str name;
        c1 = new Class1();         
        c1.setFirstName("My Name");
        name  = c1.getFirstName();
        info(strFmt("%1",name));    
}

Output:

My Name

Explanation:

No

This Particular section is dedicated to Programs only. If you want learn more about X++ Programming Language. Then you can visit below links to get more depth on this subject.