Yesterday afternoon, a colleague from Italy send me an IM asking for help on a customer scenario. The customer wants his users to see a strong warning sign attached to the item availability in the Item FactBox. The warning shall only be shown if the availability drops under a certain level. He had already experimented with the new Style property on NAV fields in SP1. He was able to show conditional formatting on the item availability field. But what the customer really wants is a more visual indication – yeah, a screaming warning icon!
On my way home in the train (public transport is just great for such tasks) I could not stop me from creating two little Add-ins as samples for that purpose. And because these two Add-ins nicely continue on the topics I have covered in part1, I decided to share this with you.
A Control Add-in may listen to its context (“context binding”)
And the result might look like this:
Combine simple data binding with context binding
The requirements for these Add-ins have been given to me:
Let translate those requirements into the world of Add-ins:
That should be doable in one train ride. Let’s code it!
A read only Add-in showing a right aligned Icon from the resources, based on the Style property of the Site - nothing simpler than that.
What is worth to mention here is the use of a Panel control as the layout container, which I return as the Add-in control. In the Panel I can easily dock the icon to the right such that it appears nicely aligned under the other values in the Factbox. A PictureBox control renders the Icon, and the Add-in must specify a proper maximum and minimum size.
The “context binding” is achieved by overriding the OnStyleChanged method which already delivers the new style. Please note: if the variable to which the NAV field property StyleExpr is bound to is false, then the Style will be “None”, otherwise it is the value of NAV field property Style.
[Description("Notification icon based on Style property")]
public class MyNotificationIconAddIn : WinFormsControlAddInBase
private PictureBox _picture;
protected override System.Windows.Forms.Control CreateControl()
Panel panel = new Panel();
Bitmap icon = StaticPicturHelper.StyleToPicture(Style.Attention);
panel.MinimumSize = new Size(icon.Size.Width, icon.Size.Height);
panel.MaximumSize = new Size(int.MaxValue, icon.Size.Height);
_picture = new PictureBox();
_picture.Visible = false;
_picture.SizeMode = PictureBoxSizeMode.AutoSize;
_picture.Dock = DockStyle.Right;
_picture.Parent = panel;
protected override void OnStyleChanged(Style style)
_picture.Visible = (style != Style.None);
_picture.Image = StaticPicturHelper.StyleToPicture(style);
Now I want to show also the value for Availability in a similar way as a standard field does. I shall look and behave like a link, with mouse over effect and all that. As mentioned above, I just need to add a Label into the layout container and handle the mouse events.
More interesting is the data binding. I decide for a different base class (StringControlAddInBase), which has some support already built in, override the Value and HasValueChanged properties, and reroute the value that arrives at the Add-in to the Label control.
And what about the click event? A mouse click event handler for all the controls (Panel, Label & Picture) triggers the ControlAddIn trigger in the Business logic on Page 9087, which in turn asks for the Drill down.
void DoOnMouseClick(object sender, MouseEventArgs e)
The ControlAddIn event allows me to send a message ID with text data. But for this Add-in I really don’t need any discriminator for different events, therefore I can specify whatever parameters here.
And this is the code that handles the event in the server side business logic. It is the standard code that executes drill down on availability.
It is time to utilize the Add-ins on the “Sales Line FactBox”. As usual, I copy the Add-in library to the Add-ins directory of the RoleTailored client and register them once with the Registration Tool.
In Page 9087 (“Sales Line FactBox”) I add a new field at the bottom for the simple Warning notification field and specify the first Add-in in the Control Add-in Property. The existing “Availability” field gets the second Control Add-in configured. Both fields get “
The variable “styleActive” is declared as a global Page variable and reflects is set by the business code for each record based on the item availability.
The fob files 9087.fob / .txt in the download material contain all changes for your review.
The last ride home on the ferry gives me time to write up this little document package the project files so I can make them available to my colleague in Italy and to you through this blog post.
I hope this information is somewhat useful and gives you a little more insight into Control Add-ins for the RoleTailored client in Dynamics NAV 2009 (SP1).
You can download the project here.
And what have I learned from this small exercise? There are a few improvements needed for the future of our Add-in model in Dynamics NAV:
However, do not worry about changes in the future now. We have one important design goal for the Add-in framework: Existing Add-ins shall be usable without changes in later releases of the NAV product.
Christian Abeln Senior Program Manager Microsoft Dynamics NAV
Ps: If you have other suggestions for useful control Add-ins, don’t hesitate to contact me – I have a train ride and a ferry home every day ;-)