You are currently viewing Goodies from the Control Add-ins session at NAV TechDays 2014

Goodies from the Control Add-ins session at NAV TechDays 2014

First of all, thank you all who attended my session today. It was a lot of people in the room, and with the competition from Microsoft talking about a very hot topic in the other, bigger room, I really wouldn’t expect to see all of you there. I hope you found the things you saw useful, and that you’ll take advantage of all the free stuff that I am posting today here on Vjeko.com.

This time I’ll split it up in different files, to make it more manageable.

Tweaking Page UI

First things first, so I start with the new “Semi-transparent Borderless Draggable Styleful Standard Dialog” page type, which in fact is not a page type but a control add-in that abuses the openness of .NET Framework to the fullest. If you have not been at the presentation, this is what it looks like:

image

And yes, it really is a page object. And it’s an extremely simple trick. You only need to call the FindForm method on the control you instantiate, and then you can do whatever you would normally be able to do with a System.Windows.Form object. Make it semitransparent. Hide the borders. Paint it in pink or something.

The code is ugly, completely optimized, dumped with a shovel and then mixed and stirred with a bazooka, it was written for the better part of it at 2 o’clock in the morning, but it proves the point. I am thinking of providing a framework which would allow you to do all those things in a more proper way that I wouldn’t be ashamed to put here, as I am to put the stuff that I’ve just put.

You can download this demo here: https://vjeko.com/wp-content/uploads/2014/11/VjekoCom.FormTweaker.zip

Drag & Drop, and BingMaps Add-ins

Then we have the Drag and Drop demo, and the BingMaps demo. I have reused my own code from earlier, so I am simply linking back to the previous demo: https://vjeko.com/blog/directions-emea-2014-content

About the Drag and Drop thing, feel free to use it as you like, and about the BingMaps demo, most of the code in there comes from Microsoft’s own blogs and demos, and I am pretty sure you are okay to reuse it as you like.

Auto-Register For Control Add-ins

The next on the list is the auto-register utility. It taps into Codeunit 1, automatically registers the add-in in the Client Add-ins table, and also automatically downloads the resource from your URL if it’s not present in the Client Add-ins. This makes sure that the control is always in place when you run an object that uses it.

Download the bits here: https://vjeko.com/wp-content/uploads/2014/11/AutoRegister.zip

Visual Studio Templates

The next are the two templates. You can use those templates in Visual Studio to quickly create JavaScript control add-ins, that automatically deploy themselves into the Client Add-ins folder, show their public key token in the Output window, and include all the structure for the resource zip file (manifest, scripts, and stylesheets).

You install the templates simply by copying them to your Documents\Visual Studio 2013\Templates\ProjectTemplates folder.

There is the simple template that includes just the mere basics, the simple interface with most basic events and methods. And there is of course the advanced template which includes the full framework (I’ll proudly call it VjekoCom.Extensibility framework Smile), and supports the dynamic creation of HTML, CSS, and dynamic execution of JavaScript, all fully controlled from C/AL.

Download the simple template here: https://vjeko.com/wp-content/uploads/2014/11/Microsoft-Dynamics-NAV-2015-Simple-Extensibility-Control.zip

Download the advanced template here: https://vjeko.com/wp-content/uploads/2014/11/Microsoft-Dynamics-NAV-2015-Advanced-Control-Add-in.zip

This advanced template is obviously work in progress, there are so many more things to be added to it, and I hope, I just hope this time it doesn’t remain at “if I have time I’ll build on top” as it happened with so many good and useful stuff I have here, and that I really turn this into a decent framework, worth sharing on CodeProject, or GitHub. or if I really have time, on NuGet.

VjekoCom.Extensibility Framework

And last but not least there is this advanced template demo, that shows the full scale of possibilities with the VjekoCom.Extensibility framework, it shows how to use the OnReadyToReceiveControlDefinition, OnChangeData, and OnJavaScriptCodeExecuted events, and how to call SendControlDefinitionToJavaScript, UpdateCss, and ExecuteJavaScript methods. In this example, C/AL creates a simple text box control with a caption in red, that changes to green and updates NAV on content change, and then C/AL executes some JavaScript code and gets notified of the completion.

And this last part is available here: https://vjeko.com/wp-content/uploads/2014/11/Extensibility_Test_Page.zip

That’s All, Folks…

Once again, thanks for joining my session. Please let me know if you found it useful, and if any of this content and demos helps you in your everyday work.

See you in the cloud, and definitely next year in Antwerp again!

Vjeko

Vjeko has been writing code for living since 1995, and he has shared his knowledge and experience in presentations, articles, blogs, and elsewhere since 2002. Hopelessly curious, passionate about technology, avid language learner no matter human or computer.

This Post Has 15 Comments

  1. Rocco

    Hi Vjeko,

    This is very handy to make a fixed screen when needed.
    Would this also be possible with WPF form stuff you think?
    (Maybe you have also an example of this :-))

    1. Vjeko

      No, I don’t have an example of WPF, but you can make a WPF container in windows forms, and then do whatever you like with it. The point here is – it’s all just a Windows Forms application, just like any other.

  2. Kevin

    Hey,

    When I try to import the AutoRegister.fob, I get an error message saying: “Codeunit 9701 does not exist.”. Any idea why and how to fix this?

    1. Vjeko

      Are you using NAV 2015?

      1. Kevin

        No, I was using 2013. Switching to 2015 should fix it then?

        1. Vjeko

          Yes, this demo code is all in NAV 2015.

  3. Matthias König

    Hi Vjeko, did you tried to change the color of a field with your Tweak UI in a repeater? I played with it (special thanks for this!!) and had the possibility to change the color of the cell Im in (with CellEnter Event) but not if its ReadOnly and not if im not in the cell. It feels NAV overwrites my settet color all the time 🙁

    Some of my customized code:
    private void SetControlBackColor(Control control, Color color)
    {

    if (control.GetType() == typeof(Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGridView))
    {
    BusinessGridView myBusinGridView = (BusinessGridView)control;

    myBusinGridView.BackgroundColor = Color.Blue;

    BusinessGridView BG = (BusinessGridView)control;
    try
    {
    BG.CellEnter += BG_CellEnter;
    }
    catch (Exception e)
    {
    MessageBox.Show(“~~” + e.Message);
    }

    }
    }

    and the Event:
    void BG_CellEnter(object sender, DataGridViewCellEventArgs e)
    {
    BusinessGridView BG = (BusinessGridView)sender;

    DataGridViewCellStyle myCellStyle = new DataGridViewCellStyle();
    myCellStyle.BackColor = System.Drawing.Color.Red;
    myCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
    myCellStyle.ForeColor = Color.White;
    BG.CurrentCell.Style.ApplyStyle(myCellStyle);

    }

    any ideas?

    Kind regards, Matthias König

    1. Vjeko

      No, sorry, I really don’t have any off-the-top-of-my-head ideas.

  4. Krisje

    Hi Vjeko, I would like to use the control addin but with a WPF UI. As I recall you told me that this is possible , but do you have a small “getting started” example somewhere ?

      1. Krisje

        Hi Vjeko,

        Thanks !
        I will try this example, looks promising :).

        Regards

  5. Matthias König

    Hi Vjeko, I have another question about the Tweaker 🙂
    I want to color only some of the fields. With control.AccessibleName I have the possibility to know which caption the control has and identify if I want to color this. I would rather do this with the control ID? Is there a possibility to get access to the NAV properties like Control ID? With EllipsisTextBox I can not reach this :/

    1. Vjeko

      I don’t know of a way to do that, sorry 🙁 As far as I could figure out, I don’t think these properties are exposed in the UI layer. I feel that the mapping between NAV control IDs and what’s visibile in the RTC object model is managed by the NST.

  6. Matthias König

    thats a pity. But then I handle it with the caption 🙂 thanks!

  7. Matthias König

    … meanwhile two years later…

    With our current NAV Version we do not know in the CAL Code if an field its editable or not.
    In my case, I want to know it without an extra variable for every field. And we do not have a “Field Metadata ” Table.

    Now I thought about this little helper here and find a strange way over “AccessibilityObject.State” of the found field.

    The “ReadOnly” and “Editable” properties are not used (if I see this correct). But if I want other properties its very complicated to search the correct one. Did you (or one of the other readers) how to solve that? An easy way to serialize that? Or any other Ideas how to “hack” that?

    (P.S. I hope its not totaly wrong to ask that here :D)

Leave a Reply