Monday, December 21, 2009

Phone Number Formatting Mask

It is pity but AX does not have the mask functionality on StringEdit fields. (versions 3.x- 4.x at least)

I changed the standard functionality for Phone field of Customers form so that the input phone number will be formatted as (xxx) xxx-xxxx[x]

For example, if one input 1234567890 it will be presented and saved as (123) 456-7890


For 12fs3.45*6.78--90 it will be presented and saved as (123) 456-7890 with no non-numericals.

12345678901234567 will be as (123) 456-7890123456 it does not truncate the tail.

If finally it does not look like (xxx) xxx-xxxx the system alerts the user about that however the input value will be saved.

The following methods were added/changed:

ClassDeclaration of Customers form

public class FormRun extends ObjectRun

boolean sisValidateCalled;

StringEdit Phone field methods:

public void enter()
sisValidateCalled = false;

public boolean validate()
boolean ret;
int length;
Phone newPhone;
ret = super();

// creates new phone number in the format (xxx) xxx-xxxx[x]
newPhone = SISTools::formatPhoneNumber(this.text());
length = strlen(newPhone);

if (length != #CorrectPhoneLettersNumber)
checkFailed(strfmt("Phone numbers should be like: (xxx) xxx-xxxx"));

CustTable.Phone = newPhone;
sisValidateCalled = true;
return ret;
public boolean leave()
boolean ret;

ret = super();

if (!sisValidateCalled)

return ret;

SISTools class (some collection of utilities)

// creates new phone number in the format (xxx) xxx-xxxx[x]
static public Phone formatPhoneNumber(Phone _phone = "")
Phone newPhone = "";
str char;
int length = strlen(_phone);
int i;
container numbers = ['0','1','2','3','4','5','6','7','8','9'];
// remove all non numbers from field text
for (i=1; i<=length; i++)
char = substr(_phone,i,1);
if (confind(numbers,char))
newPhone = newPhone + char;
length = strlen(newPhone);

// create new phone number in the format (xxx) xxx-xxxx from 1234567890
newPhone = "(" + substr(newPhone,1,3) + ") " + substr(newPhone,4,3) + "-" + substr(newPhone,7, length-6);

return newPhone;

Inspired by Sonny Wibaba Adi

Friday, December 4, 2009

Flush Events related tables quickly

Quick job to delete all records from Events related tables. Inspired by this posting of Nitesh Ranjan.

static void FlushEventInbox(Args _args)
To implement Alert functionality, Dynamics AX uses following tables:

|- EventInboxData
|- EventRule
EventRuleRelData EventRuleRelData;
EventRuleRel EventRuleRel;
EventRuleIgnoreAggregation EventRuleIgnoreAggregation;
EventRuleIgnore EventRuleIgnore;
EventRuleField EventRuleField;
EventRuleData EventRuleData;
EventRule EventRule;
EventInboxData EventInboxData;
EventInbox EventInbox;
if (Box::okCancel("Flush all Events related table?", DialogButton::Cancel, "Confirm deletion",
"Delete all records from: delete_from EventRuleRelData, EventRuleRel,"
+" EventRuleIgnoreAggregation, EventRuleIgnore, EventRuleField, EventRuleData,"
+" EventRule, EventInboxData, EventInbox") == DialogButton::Ok)
delete_from EventRuleRelData;
delete_from EventRuleRel;
delete_from EventRuleIgnoreAggregation;
delete_from EventRuleIgnore;
delete_from EventRuleField;
delete_from EventRuleData;
delete_from EventRule;
delete_from EventInboxData;
delete_from EventInbox;


Tuesday, December 1, 2009

How to add all descendant classes to a new project

I bumped into the problem of a class compilation with no licence for X++ source code.

Forward compile option is not enough to make my changes working. Thus I need to export-import all descendant classes as well as the class I changed - FormLetter in my case.

I therefore have to add all these classes to my project. Natural laziness saved me again from this manual work.

I hope this short job inspired by system class SysCompilerOutput and miklenew's job from AXForum will help you in similar situations.

// add to a new project all descendant classes for forward compilation
public static void SISCreateCompileForwardProject(Args _args)
str project = 'SIS_CompileForward';
SysCompilerOutput sysCompilerOutput;
Dictionary dictionary = new Dictionary();
DictClass dictClass = new DictClass(className2Id("Formletter"));
int numOfClasses = dictionary.classCnt();
ProjectNode sharedProjects;
ProjectNode newProject;

void addToProjectForwardClass(DictClass _dictClass, Dictionary _dictionary, int _numOfClasses)
ClassNode classNode;
DictClass dictClassLoop;
DictClass childClass;
int i;
if (_dictClass)
classNode = infolog.findNode(#ClassesPath + #AOTDelimiter +;

if (classNode)

for (i=1; i <= _numOfClasses; i++)
dictClassLoop = _dictionary.classObject(_dictionary.classCnt2Id(i));

if (dictClassLoop.extend() ==
childClass = new DictClass(;
addToProjectForwardClass(childClass, _dictionary, _numOfClasses);

sharedProjects = infolog.projectRootNode().AOTfindChild('Shared');
newProject = sharedProjects.AOTfindChild(project);
newProject = newProject.getRunNode();
addToProjectForwardClass(dictClass, dictionary, numOfClasses);