why we use the chain of command in Ax 7

Hi,

Someone tell me with example ,why we use the chain of command in Ax 7.

Hi

Please look into this link where you can get a clear view of Chain of Commands.

Chain Of Commands

Hi Thomas,

I have read the above link but i have confused when I have to use the coc and pre and post event handler.

I have doubt in code flow of the pre and post event handler in Ax 7.

Please explain

CoC is a much better alternative to pre-/post-method event handlers. You can refer to parameters by name, you get compile-time control, it’s easier to read and so on.

You’ll have to explain your doubt (“I have doubt in code flow of the pre and post event handler”) if you want us to comment on it.

Hi Martin,

Thanks for your reply.

see the COC below example code,

table custbankaccount.validatefield method is called first when it come to the next validatefield() line, is it correct.

[ExtensionOf(tableStr(CustBankAccount))]
final class CustBankAccount_Extension
{
public boolean validateField(fieldId _fieldId)
{
boolean ret;
next validateField(_fieldId);
switch (_fieldId)
{
case fieldNum(CustBankAccount, Email) :
break;
}
return ret;
}

In below example of preeventhandler “CustTransOpen_Pre_init” method is called first and then “CustTransOpen” form init() is called is it correct code flow.

class CustTransOpen_EventHandler
{
[PreHandlerFor(formStr(CustTransOpen), formMethodStr(CustTransOpen, init))]
public static void CustTransOpen_Pre_init(XppPrePostArgs _args)
{
FormRun formRun = _args.getThis();

if (!formRun.args() || !formRun.args().caller())
{
if (formRun.args().dataset() == tablenum(CustOverduePayments))
{
DictClass dictClass = new DictClass(classIdGet(formRun));
dictClass.callObject(‘CustOverduePayments’, formRun, formRun.args().record());
}
}
}

In below example of the post event handler “CustTransOpen” form init() is called first then event handler method “CustTransOpen_Post_init” is called is it correct.

[PostHandlerFor(formStr(CustTransOpen), formMethodStr(CustTransOpen, init))]
public static void CustTransOpen_Post_init(XppPrePostArgs _args)
{
FormRun formRun = _args.getThis();
FormStringControl InvoiceId = formRun.design().controlName(formControlStr(CustTransOpen, InvoiceId)) as FormStringControl;
FormStringControl ECL_SalesFrequency = formRun.design().controlName(formControlStr(CustTransOpen, ECL_SalesFrequency)) as FormStringControl;

InvoiceId.visible(false);
ECL_SalesFrequency.visible(false);

DictClass dictClass = new DictClass(classIdGet(formRun));
CustOverduePayments CustOverduePayments = dictClass.callObject(‘CustOverduePayments’, formRun);

if (CustOverduePayments)
{
InvoiceId.visible(true);
ECL_SalesFrequency.visible(true);
}

}

}

Can you please use Insert > Insert Code for source code? It’s almost unreadable without indentation.

I have only above code so can you explain with your code.

I want to know the code execution flow of the pre an post event handler in Ax 7.

All right, let me do it for you this time, but please make sure you do it correctly by yourself next time. It’s in your own interest; you shouldn’t make it so difficult for people who could help you.

I’ve also added question marks in text and missing closing brackets in code.

Table custbankaccount.validatefield method is called first when it come to the next validatefield() line, is it correct?

[ExtensionOf(tableStr(CustBankAccount))]
final class CustBankAccount_Extension
{
    public boolean validateField(fieldId _fieldId)
    {
        boolean ret;
        next validateField(_fieldId);
        switch (_fieldId)
        {
            case fieldNum(CustBankAccount, Email) :
            break;
        }
        return ret;
    }
}

In below example of preeventhandler “CustTransOpen_Pre_init” method is called first and then “CustTransOpen” form init() is called is it correct code flow?

class CustTransOpen_EventHandler
{
    [PreHandlerFor(formStr(CustTransOpen), formMethodStr(CustTransOpen, init))]
    public static void CustTransOpen_Pre_init(XppPrePostArgs _args)
    {
        FormRun formRun = _args.getThis();

        if (!formRun.args() || !formRun.args().caller())
        {
            if (formRun.args().dataset() == tablenum(CustOverduePayments))
            {
                DictClass dictClass = new DictClass(classIdGet(formRun));
                dictClass.callObject('CustOverduePayments', formRun, formRun.args().record());
            }
        }
    }
}

In below example of the post event handler “CustTransOpen” form init() is called first then event handler method “CustTransOpen_Post_init” is called is it correct?

[PostHandlerFor(formStr(CustTransOpen), formMethodStr(CustTransOpen, init))]
public static void CustTransOpen_Post_init(XppPrePostArgs _args)
{
	FormRun formRun = _args.getThis();
	FormStringControl InvoiceId = formRun.design().controlName(formControlStr(CustTransOpen, InvoiceId)) as FormStringControl;
	FormStringControl ECL_SalesFrequency = formRun.design().controlName(formControlStr(CustTransOpen, ECL_SalesFrequency)) as FormStringControl;

	InvoiceId.visible(false);
	ECL_SalesFrequency.visible(false);

	DictClass dictClass = new DictClass(classIdGet(formRun));
	CustOverduePayments CustOverduePayments = dictClass.callObject('CustOverduePayments', formRun);

	if (CustOverduePayments)
	{
		InvoiceId.visible(true);
		ECL_SalesFrequency.visible(true);
	}
}

Yes, pre-handler is called before the method and post-handler is called after that. In CoC, the method is executed by next, therefore code before next is called before the method and code after next after the method.

Hi Martin,

Thanks for your reply.

I have misunderstood that your asking me the code for insert method example but your asked to align the code.

next time i will align the code properly.