AX / D365FO – Check if a FormControl is of type “String”, “Date” or “numeric”

I often work with FormControls and need to understand the type of control in order to use the right properties and methods.

The code below shows how to intercept the control type and cast it with the matching type

public void getFormControlType(FormControl _myFormControl)
	FormRealControl     callingRealControl;
	FormStringControl   callingStringControl;
	FormIntControl      callingIntControl;
	FormInt64Control    callingInt64Control;
	FormDateControl     callingDateControl;

	switch (_myFormControl.handle())
		case classNum(FormRealControl):
			callingRealControl = _myFormControl;  //This is a real type
			callingRealControl..... //Insert your code here
		case classNum(FormStringControl):
			callingStringControl = _myFormControl;  //This is a String type
			callingStringControl.....//Insert your code here
		case classNum(FormIntControl):
			callingIntControl = _myFormControl; //This is an Int type
			callingIntControl.....//Insert your code here
		case classNum(FormInt64Control):
			callingInt64Control = _myFormControl; //This is an Int64 type
			callingInt64Control.....//Insert your code here
		case classNum(FormDateControl):
			callingDateControl = _myFormControl; //This is a Date type
			callingDateControl.....//Insert your code here

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s