Pages

Monday, December 12, 2011

Color code forms in AX 2012, depending on environment/company


One thing that you might miss in the AX client is as a higher visibility of which company and environment that you’re working in. I have seen plenty of solutions where the entire background of forms is colored according to the current company, making each form look like something the cat has coughed up.

The least intrusive solution and the only one I have taken time to modify a bit and implemented at a customer is the one made by Arijit Basu. I have modified it, allowing you to choose your own color and a customer text per AOS. Since not all forms are designed entirely correct, the solution unfortunately doesn’t work as expected on all forms.

In AX 2012 the game has changed, because there is no background left on the forms to color. But the good folks at Microsoft has anticipated that we want to do some coloring still, and there’s a new method on FormRun which allows you to color the background of the statusbar; setStatusBarBackgroundColor.

I have made a solution using this method. The solution allows you to select a color per database server, database and company. If you don’t specify a company, the color works for all companies on the selected server and database.

I have included database server and name to support the scenario where you copy your production database to a test database. This way you can setup the indication for working in the test environment from your production system and you don’t need to add any information after having copied production data to test.

The solution is absolutely version 1, but I expect to add more features for the visualization in the time to come. One thing I’d like to add as soon as possible is some kind of identification in the infolog.
I have one known issue with the solution, which is that the lookups on database server and database don’t quite show all the servers and databases that I expected. I’ll look into that at some point, but any hints are welcome.

Example of form:



You can download the solution as an XPO or a model file from my SkyDrive.

11 comments:

pladeKusken said...

Nice!
PS:
Metode:setFormStatusBarColor()
Why?
a = 254;
BR,
René

Palle Agermark said...

The a is the alpha channel of the color. To my understanding you can tweak this value to make the color transparent. The value 254 is something I have copied from similar standard AX code.

Cheers,
Palle

Kilsgaard said...

Hi

Thanks for this great post..

Is there any solution, how to show the color code allready when the Ax 2012 client is startet?

Regards
Graves

Palle Agermark said...

I haven't figured out how to do that yet.

Palle Agermark said...

Here's another take on the same requirement:
http://blogs.msdn.com/b/axsupport/archive/2012/10/12/changing-the-background-color-on-ax-forms-in-ax-2012.aspx

siyer123 said...

I downloaded your xpo but was to import the model file so was giving many errors.
I searched on Technet about Form statusbar background color http://msdn.microsoft.com/en-us/library/formrun.setstatusbarbackgroundcolor.aspx

I am able to change the form color by this code
this.design().backgroundColor(WinApi::RGB2int(152,251,152));
this.setStatusBackgroundColor(152,251,152,0.94)); //RGBA
but it chnages the status bar to black. I want light green color

rlongia said...

Hi Palle Agermark,

This solution will work for ax 2012 r3 too, can i have the download link for the xpo.

Palle Agermark said...

You should be able to just click the embedded file icon

rlongia said...

@Palle Agermark

I am sorry but below link has no embedded file icon, or do i need to goto some other place to download the file.

Also please let me know if this solution will also work on R3 cu7 or later aswell?

http://www.agermark.com/2011/12/color-code-forms-in-ax-2012-depending.html

Amber Rains said...

We use the following code
public static str getEnvironment()
{
Session session = new Session();
#define.axDevAos('AXDEVAOS')
#define.port2712(2712)
#define.port2713(2713)
;

switch (session.AosName())
{
case #axDevAos:
switch (getPort())
{
case #port2712:
return 'Development';
case #port2713:
return 'Test';
}
...etc
}
}

public server static int getPort()
{
Session session = new Session();
SysServerSessions serverSessions;
SysClientSessions clientSessions;
int ind;
str aosId, port;
;
select firstOnly clientSessions where clientSessions.SessionId == session.sessionId();
if (!clientSessions)
return -1;
select firstonly serverSessions where serverSessions.ServerId == clientSessions.ServerId;
if (!serverSessions)
return -1;
aosId = serverSessions.AOSId;
ind = strFind(aosId, '@', 0, strlen(aosId));
port = substr(aosId, ind + 1, strlen(aosId) - ind);
return str2int(port);
}

hs said...

Thanks a lot. Valuable post.