Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 1 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
The last of the NAV TechDays 2018 demo series comes with a little story.
And that was it! An amazingly cool demo that shows how you can do really cool stuff that falls beyond the visual realm.
Okay, I’ll calm down a bit. Keyboard shortcuts? Seriously? Well, unfortunately, yes. In NAV/BC web client (universal client included) there are almost no keyboard shortcuts. Microsoft is working on some improvements here, but the important thing, allowing developers to bind specific keyboard shortcuts to specific actions, is still conspicuously missing from NAV/BC.
So, I did this demo.
Let me first explain what the demo does.
Just like the profile picture demo, this one is a 1 x 1 “invisible” control add-in that injects some keyboard event listeners in the web client. However, since the web client in NAV 2018 and BC is full of IFRAMEs, I had to inject the event listeners all over the place, so the first thing that the demo does is that it locates all IFRAMEs in the current context and injects the capture event listener for keyboard events in all of them, so it kind of has the priority in handling keyboard input no matter where the focus currently is in the application. That’s the simple part.
The difficult part comes when the keyboard is successfully pressed. What then? In theory, you invoke an event in AL, and that event runs the action that you want to run, but this only works in theory. In practice, you cannot invoke a page action from code. I had two options.
The first one was to do duplicate quite a bit of code in AL simply to be able to demo a single keypress. Waldo preferred me showing document posting invocation through a keypress, but that would involve me copying quite a bit of code on the page so I could invoke exactly the same functionality that’s invoked when the Post action is clicked. However, I wanted to demo how easy it is to extend this by adding one simple line of AL code to bind another keystroke to another action. And since that would involve me duplicating large amounts of page code in front of the audience (and it will be a cold day in hell before you see me demo anything that involves code duplication) I chose another path.
The first problem I solved by specifying the action binding through a combination of caption (something known in AL) and icon (also known in AL). If the action is rendered in the page, I can locate its DOM element through the icon it shows and caption it displays. That thing was fairly easy to solve, and you can see it in the demo code how I did it.
The second problem is entirely smoke and mirrors. What I did while demoing was that I expanded the tab (or opened the submenu) that contained the action I wanted to invoke, and then pressed the keyboard shortcut. So – I didn’t cheat with the actual keyboard shortcut, it really and truly was the keyboard shortcut that invoked the action. But I did cheat in the fact that if the action hadn’t been physically visible on the page, I wouldn’t have been able to invoke it.
Am I embarrassed because of this? Absolutely not. If anyone should be embarrassed of this, then it’s Microsoft, that from version to version keeps the remnants of the old “architecture” in place – instead of solving the problem on the AL level the way it should be solved (applying some nice, well-documented patterns, and getting rid of some ugly, well-known anti patterns like putting large chunks of code in pages) I wouldn’t have to invoke any voodoo here to make it work. However, with the state of the page “architecture” at where it still unfortunately is, I had no other option.
But it worked. And it doesn’t render this demo any less interesting. I actually find this demo the best and most useful of all demos, because it shows how you can capture a shortcut and then propagate it all the way back to AL where you can choose how to handle it. In this demo I didn’t propagate it – it was handled entirely in the front end – but it would take exactly one line of code to send the captured shortcut back to AL for processing.
And that’s it. A cool and simple demo
You can find all the code for this demo in this GitHub repo: https://github.com/vjekob/controladdin-keyboardshortcut
And again, there are two branches in there, master for BC, and nav2018 for – duh! – NAV 2018.
Happy keyboarding, and see you soon in another post! (most likely, not today, enough is enough )
The post NAV TechDays 2018 Demos: Keyboard Shortcut Listener appeared first on Vjeko.com.
Business Applications communities