Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

hotkey for contact search

Posted on by Microsoft Employee

I am trying to write js in a web resource to create a hotkey for activating the contact search field. So far I have this:

parent.document.onkeyup = function(e) {
var e = e || window.event;
if (e.altKey && e.which == 65) {
alert ('keyboard shortcut working!');
return false;
}
}

Above creates the hotkey, but I cannot find the ID for the search input field, and I suppose I'm unsure of how to call it in js as well. 

Capturejs.PNG

Any help appreciated.

Regards,

Christine

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: hotkey for contact search

    Michel,

    Yeah, I did that. But it still doesn't work everywhere.. I'm confused as to why though.

    This is where I put it.

    global4.PNG

    -Christine

  • Suggested answer
    Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: hotkey for contact search

    Hey Christine,

    1. Create a new solution in your organization and add under 'Client Extensions' add 'Application Ribbons'

      dynamicscommunity_5F00_addapplicationribbon.png

    2. Use the third party application 'Ribbon Workbench' to open your newly created solution and there you can edit the application ribbon and add your javascript.

      Ribbon Workbench can be downloaded as part of XRM Toolbox: https://www.xrmtoolbox.com - a great multi tool for developing Dynamics solutions
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: hotkey for contact search

    Hi Michel,

    I've been working on it for a while now and am having trouble making it available globally. I was thinking of adding the js web resource in the application ribbon, but I don't know where.. Any advice?? Hope your day's going well.

    -Christine

  • Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: hotkey for contact search

    Any time, Christine. Here to help :-)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: hotkey for contact search

    Michel,

    No jQuery, got it. I guess I will try to make the web resource available globally then. Thanks so much for all your help today. I appreciate you taking the time to explain some things to me!

    -Christine

  • Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: hotkey for contact search

    Hello Christine,

    My guess would be that the javascript event gets unregistered or not loaded locally, because Dynamics loads and unloads pages in various levels of isolation, which may just cause your script to be unloaded.

    Also, the focus of your keyboard is in different iframes at different times. It's not very noticeable but, the Dynamics user interface in the browser is built up out of many different iframes, unless you register your event hook in all of them, there will always be a chance that your current keyboard focus is in an iframe that doesn't have it.

    .

    As for using jQuery, which I assume you are trying to use, going by the famous $; please don't use that. You'll break some internal Dynamics scripts for sure, as they also use jQuery but, probably a different version you need/use. Stick to vanilla (plain, no frameworks) javascript in Dynamics.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: hotkey for contact search

    Hi Michel,

    Thanks for your speedy reply. I understand, and I appreciate your warning. As soon as I can get it working for my boss, I will look into other, supported options (kind of on a time crunch). That does work, however it only works once out of about every five attempts. Is there something I'm missing? It seems like once it calls the function, it won't do it again for a certain amount of time. I'm pretty new to programming in general, so I may be missing a fundamental part of knowledge to debug this. If you could help explain that phenomenon, I would appreciate it tons.

    -Christine

    EDIT: would the following work to resolve the problem mentioned above, and be supported?

    $(document).on('pageinit', function(e)

    rather than

    parent.document.onkeyup = function(e)

  • Verified answer
    Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: hotkey for contact search

    Hello Christine,

    What you are trying to do is an unsupported customization and will break the application in a future version.

    I highly discourage you from implementing this type of customization.

    .

    That being said, the element you are looking for is called "ms-crm-FindButton"

    You can trigger it to open by running this JS:

    window.top.document.querySelector(".ms-crm-FindButton").click();

    But... again... warning: this is an unsupported customization, if you break something, Microsoft will not help you fix it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans