From July 9th till 13th we will be at #MSInspire. See you there!

X++ tips and tricks: Passing parameters in Microsoft Dynamics AX

23 Feb 2014

Args is your companion in the world of X++ especially when passing parameters in Microsoft Dynamics AX. Args is an abbreviation for arguments. It allows you to pass information from one object to another newly created object. I utilize it frequently to pass the objects, records, strings, etc that I need to have in scope while accessing the object from another object. It’s very easy to utilize the Args class to get the desired result you’re looking for.

The following example demonstrates how to create an instance of the Args class:

Declaration of Args

Args  args = new Args();
CustTable  custTable;

Setting record is Args

select custTable where custTable.AccountNum == ‘XXXX’

if(custTable)
{
args.record(custTable);
}

 

Some important methods of Args class

Caller

Get or sets the instance of the object that created this instance of the Args class.

Name

Gets and sets the name of the application object to call.

Parm

Gets or sets a string that specifies miscellaneous information for the called object.

parmEnum

Gets or sets the enumeration value of the enumeration type that is specified in the parmEnumType method.

parmEnmType

Gets or sets the ID value of any enumeration type.

ParmObject

Gets or sets an instance of any object to pass, to the called object.

Record

Gets and sets the record from the table on which the caller object is working.

 

Sample Code  For Setting Value in Args

Create an instance of the Args and custom class.

 Args  args;
CustTable  custTable;
//custom class object to pass
Student student= new Student();
args = new args();

Set the parameter which you want to pass. If you just want to pass a simple string you can do it like this

 args.parm("Hello World");

If you want to pass an enum value you can do so via following code.

args.parmEnum( NoYesEnumValue.selection() );
args.parmEnumType( EnumNum( NoYes ) );

If you want to pass table buffer  in parameter

args.record( EmplTable );

If we want pass a more complex set of parameters, you can develop your own class just for passing those parameters.

student.parmName(‘William’ );
student.parmRollNum(‘st-123‘);
args.parmObject(student);

If you to pass records from a table, use following code.

select custTable where custTable.AccountNum == ‘XXXX’

if(custTable)
{
args.record(custTable);
}

 

Sample Code  For Getting  Value From Args

Create an instance of the Args class and your custom class.

Args   args;
CustTable  custTable;
//custom class object to pass
Student student= new Student();
args = new args();

Check that the passed arguments are not null

if( element.args() )
{
.....
}

Get string value

strValue.text( element.args().parm() );

Check parmEnum is not null and then get enum parameter

if( element.args().parmEnumType() == EnumNum( NoYes ) )
{
NoYesEnumValue.selection( element.args().parmEnum() );
}

Check parmEnum is not null and then get object

if( element.args().parmObject() )
{
student = element.args().parmObject();
}

Check that the table buffer is not null and then get record.

if( element.args().record() && element.args().record().TableId == TableNum( CustTable ) )
{
custTable=  element.args().record();
}

ABOUT Folio3 Dynamics Services

As Dynamics AX experts we specialize in Dynamics AX development including Dynamics AX customization, integration, implementation and mobility solutions. If you have a Dynamics AX development requirement you would like to discuss or would like to know more about our Dynamics AX development services, please get in touch with us.

1. What is X++ programming language used for?

X++ is a high level object oriented language with robust data access features. It is often used to create management systems pertaining to businesses, their accounts and finances, and many other business processes. You may be wondering why you need X++ for Microsoft Dynamics when a powerful language C# is already present. This is because X++ is more appropriate for ERP systems and business management systems and is tailor-made for such. It can also combine processing code and SQL easily, which comes as an advantage in making such systems.

2. How can I learn X++ programming language for Dynamics 365?

It would be much easier to understand X++ if you already know another programming language. If not, then it would be better to first learn the basics of object oriented programming in general. What can also help is getting your hands on “Inside Microsoft Dynamics AX”, a book by Microsoft, so that you can increase your knowledge, learn beyond just X++ and understand Dynamics in detail.

Microsoft offers a X++ Language Programming Guide, which you can further go through to learn the language. Microsoft also offers System and Application classes to help you better understand system programming and the management of different business processes. If you want to perfect what you learn, then you can also go through and run a few sample codes available on the Internet to get a better grip on the language.

Share

Raza Rabbani

Latest From Our Blog
Difference between Dynamics CRM and the Dynamic...
Record a Purchase Invoice In Dynamics AX
November 28, 2019
Read more
7 Ways Dynamics 365 Finance and Operations Boos...
dynamics 365 finance
November 9, 2018
Introduction Launched by Microsoft, Dynamics 365 ERP is one of the most effective for businesses today. It is perfect to save the time, effort and ...
Read more
The Ultimate Guide to Dynamics 365 HR Payroll P...
dynamics hr payroll
October 30, 2018
For any business, irrespective of its size, payroll processing is one of the most important functions. Payroll processing is a method through which...
Read more