Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Inject Javascript dependency inside a custom ribbon button

Posted on by Microsoft Employee

Hey guys, 

this is a pretty specific question. 

Javascript A: 

function onclick() {
    test();
}

Javascript B: 

function test() {
 alert ('works');
}

I have custom Ribbon Button Test which is configured to call onclick() inside of Javascript A.

pastedimage1574873603635v2.png

I also added Javascript B as a dependecy of Javascript A. 

But somehow, if I click on my button, I can't access the test() function.

Crash Report: 

CrashReport:
		FileName:/tools/Solution/home_solution.aspx
		LineNumber:0
		Function:signIn
		ErrorReport:
  1.0
   XMLHandler
   {4edd0170-86c6-4bdd-9a85-7a5575ba0248}
  
   test is not defined
   0
   0
   /tools/Solution/home_solution.aspx?etc=7100&sitemappath=Settings|Customizations|nav_solution&pagemode=iframe
   /tools/Solution/home_solution.aspx?etc=7100&sitemappath=Settings|Customizations|nav_solution&pagemode=iframe
   signIn
   
   $webresource:cr8e3_authJS
   
ReferenceError: test is not defined
    at signIn (:3:1)
    at Function.Mscrm.Utilities.executeJavascriptFunction (https://crm4.dynamics.com/_common/global.ashx?ver=-330508:6872:600137)
    at Mscrm.CommandHandler.$Cu_1 (https://crm4.dynamics.com/_static/_controls/ribbon/ribbon.js?ver=-330508:1:82816)
    at Mscrm.CommandHandler.$Ap_1 (https://crm4.dynamics.com/_static/_controls/ribbon/ribbon.js?ver=-330508:1:82156)
    at Mscrm.CommandHandler.handleCommand (https://crm4.dynamics.com/_static/_controls/ribbon/ribbon.js?ver=-330508:1:77067)
    at Mscrm.CommandBarData.executeCommand (https:/crm4.dynamics.com/_static/_controls/ribbon/ribbon.js?ver=-330508:1:146512)
    at Mscrm.ButtonControl.executeCommand (https://crm4.dynamics.com/_static/_controls/ribbon/ribbon.js?ver=-330508:1:60031)
    at Mscrm.ButtonControl.click (https://crm4.dynamics.com/_static/_controls/ribbon/ribbon.js?ver=-330508:1:56116)
    at Mscrm.CommandBar.onClickHandler (https://crm4.dynamics.com/_static/_controls/ribbon/ribbon.js?ver=-330508:1:22257)
    at HTMLAnchorElement.cd (https://r1.res.office365.com/o365/versionless/shellcoreming2am_35b8ea41.js:58:18)
 

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Inject Javascript dependency inside a custom ribbon button

    Discovered this just 3 minutes before you ;) But thank though!

  • Verified answer
    DynamicsAlex Profile Picture
    DynamicsAlex 25 on at
    RE: Inject Javascript dependency inside a custom ribbon button

    You must somehow "load" JavascriptB in the ribbon for it to be recognized, the "dependencies" thing I believe is meant for forms.

    Simply add another JavascriptFunction to the CommandDefinition *before* invokign test();  this new command should point to JavascriptB. As a function, you can use isNaN with no parameters.

    You'll end up with a CommandDefinition looking like this:

    > WebResource: JavascriptB    Function: isNaN

    > WebResource: JavascriptA    Function: test

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Inject Javascript dependency inside a custom ribbon button

    Found the issue. I had to add the referenced Javascript B in the Ribbon Workbench Command for Javascript A with Functionname "isNaN".

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Inject Javascript dependency inside a custom ribbon button

    I can see the error says test is not defined in the web resource. Are those function you wrote in same webresource?

    If I am not wrong there might be some issue with the file which you referenced in ribbon workbench.

    Apart from above two functions ,is there any other code you wrote in the web resource? Check the file carefully , better to put all the code in VS editor to find any syntax errir might be somewhere apart from those function in the Js file having issue.

    You can create new JS web resource with above function and then reference that file in ribbon workbench.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans