Search This Blog

Friday 6 November 2015

Check the name of the calling object on the Form in Dynamics AX 2009

Some times on the form we need to check which object called this form and based on the calling object we do some changes on the form.

if the type of the calling object is class than below is the code inside if check through which we can identify the name of the caller class:

 if(SysDictClass::isEqualorSuperclass(classidget(element.args().caller()), classnum(nameoftheclass)))
{
     //write some logic to do some changes on the form if the caller class is the same is you check
}

if the type of the calling object is menuitem than below is the code:

if(this.formRun().args().menuItemName() == (menuItemDisplayStr(HcmUpdateToForecastPosition))
{
  //write some logic to do some changes on the form if the caller menuitem is the same as you           check 
}

if the type of calling object is form than below is the code:

Object  formRunObject;//write this in the class declaration of the form

//write below code in the init method of the form

formRunObject = element.

if (element.args().caller())
{
     formRunObject = element.args().caller();

     if(formRunObject.name() == formstr(ProjInvoiceTable))
     {
          //write some logic to do some changes on the form if the caller menuitem is the same as                //you check
     }
}

This are the three ways in which we can check the names of calling object.

you can write these code in the init method.

if you have any questions on this than feel free to comment on it.

Thanks
Muhammad Zahid