Friday 18 March 2016

How to change form color by company in Microsoft Dynamics AX 2012

How to change color based on the company in Microsoft Dynamics AX 2012


I came across the client’s new requirement in Microsoft dynamics ax 2012 that, they want to identify in which company they are currently working by the color. On the base of color they define the company.

The issue is users are working on the same form with multiple legal entity at a time. This causes them the issue of data capturing. By mistake entering in wrong legal entity. On the base of color they can easily identify the company.
Here is the list of steps which we follow
  • Create Extended datatype
  • Create Table “CompanyColor”
  • Add Table to OMLegalEntity form
  • Create methods on the form
  • Edit class SysSetupFormRun
  • Set company wise color
  • Result


Extended datatype
  1. CompanyformColor
  2. CompanyID


Create Table “CompanyColor”
Fields
  1. CompanyformColor – Real, attach extended data type “CompanyFormColor”
  2. CompanyId – String, attach extended data type “CompanyID”


Add Table to OMLegalEntity form
Open data source and create new data source and add Table Created above “CompanyColor”
Open Design and Create new Tab under “General Tab” and drag CompanyformColor field from the CompanyColor table
Add lookup Method on CompanyformColor field
public void lookup()
{


   int red;
   int green;
   int blue;
   container color;


   [red, green, blue] = WinApi::RGBint2Con(
                   CompanyColor_CompanyFormColor.backgroundColor());
                   color = WinAPI::chooseColor(
                   element.hWnd(),
                   red,
                   green,
                   blue,
                   null,
                   true);


   if (color)
   {
   [red, green, blue] = color;
   CompanyColor1.CompanyFormColor = WinAPI::RGB2int(red,green,blue);
   CompanyColor_CompanyFormColor.backgroundColor(real2int(CompanyColor1.CompanyFormColor));
   }
}


Add modified Method on CompanyformColor field


public boolean modified()
{
   boolean ret;


   ret = super();


   //if no company color exists, delete the CompanyColor record
   if (!CompanyColor1.CompanyFormColor)
   {
       CompanyColor1.delete();
   }


   return ret;
}


Edit class SysSetupFormRun
public void run()
{
   FormTabControl   tab;
   //ChangeTabPageColors changeTabPageColors;
   int companyColor;
   ;


   super();


   // Switch and based on the current company change colors, or not for default
   if (CompanyColor::find(curext()).CompanyFormColor)
   {
       // Set the color scheme of this instance of the SysFormRun to RGB
       companyColor = real2int(CompanyColor::find(curext()).CompanyFormColor);
        
// code here to apply color to control       

       
   }
}


Set Color for the legal entity
Go to > Organization administration > setup > legal entities. Select the legal entity and select color


Restart the AX client, here is the result


This helped you..!! Then hit the ads on the page..:)


No comments:

Post a Comment