Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

Posted on by 115

Hello guys,

I have problem with Ribbon Workbench. I want to add button on homepage grid and add JavaScript on it.

I've added a test JS and added button in solution. I can see button but it doesn't work.

4188.ribbon.PNG

When I go to developer tools I can't see JS which means that button is not connected with JS.

Can you help me to set up button in Ribbon Workbench for button to work? Do I need to add Display or Enable rule maybe? I don't know what to do because I use RW for buttons on form and it works properly.

Btw JS code is proper and simple just to test.

This is how I set button.

6254.rw.PNG

Any feedback would be grateful

*This post is locked for comments

  • AndreyAndrey Profile Picture
    AndreyAndrey 25 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    Hello Marina,

    I have a button which run a WF on the Form and I am trying to make it work from the HomepageGrid, but I can't get how to change it to make it work.
    Here is the code working on the button on the Form:

    function createRevision() {

    executeWorkflow(
    Xrm.Page.data.entity.getId(),
    "5ED7322B-AF9C-4DEC-8524-D9AA1EA6073A",
    Xrm.Page.context.getClientUrl());

    //alert("Text" + Xrm.Page.getAttribute("<fieldschemaname>").getValue());
    Xrm.Page.data.refresh(true);
    }

    function executeWorkflow(entityId, workflowId, clientUrl) {
    var functionName = "executeWorkflow >>";
    var query = "";
    try {

    //Define the query to execute the action
    query = "workflows(" + workflowId.replace("}", "").replace("{", "") + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow";

    var data = {
    "EntityId": entityId.replace("}", "").replace("{", "")
    };

    //Create request
    //request url
    var req = new XMLHttpRequest();
    req.open("POST", clientUrl + "/api/data/v8.2/" + query, false);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");

    req.onreadystatechange = function () {

    if (this.readyState == 4 /* complete */) {
    req.onreadystatechange = null;

    if (this.status == 200) {
    //success callback this returns null since no return value available.
    var result = JSON.parse(this.response);


    } else {
    //error callback
    var error = JSON.parse(this.response).error;
    }
    }
    };
    req.send(JSON.stringify(data));

    } catch (e) {
    throwError(functionName, e);
    }
    }

    And here is the command setting for the button:

    2438.jpg

    Could you advise on how to do it?

  • Ivan Burda Profile Picture
    Ivan Burda 115 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    Hi Marina,

    Thank you for your answer! That help me a lot!

    Best Regards

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    Hello Ivan,

    The thing is, that is not the same thing when you put button on regular form and on homepage grid.

    When you put button on homepage grid, you must send selected items as a parameter.

    So, on RW command, add CRM parameter= SelectedControlSelectedItemIds

    And your javascript function will look something like this:

    function MyFuncton(selectedItems)

    {

    //go through a list of selected item IDs and do what you need...

    }

    Hope this helps!

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    Try to create new button with only simple function see how it goes .

  • FabioG Profile Picture
    FabioG 130 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    First of all on Ribbon Workbench you need:

    - add button where you need

    - specify core command of what you need to do

    - publish the solution

    on command core you need:

    - specify the custom action with the library you are using for and the action (crmAccount.js for example the library and the action "DoSomething" as function)

    on the Account entity you need to add a library (web resource) that have the same name (crmAccount.js), edit it with the function above:

    function DoSomething() {

       debugger;

       //do something

    }

    - save and publish

    ctrl +f5 or clear cache and retry your operation

  • Ivan Burda Profile Picture
    Ivan Burda 115 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    Here is JS for this button

    7607.js.PNG

    I tried with the debugger and without it and will not work

    thanks for the answers

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    You can not see  derectly  ribbon  action webresource in   F12 debugger window  ,however   you  can  search by function name in the F12 window search box , you can find the function which loaded with internal script and put debugger on it. In this way you may get more than one place  same function are there, this is happen if  same webresource attached  in the form library..

  • ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    Andrew is on the money - you won’t see the web resources loaded in F12 because of the dynamic script loading. The script will not even load until the command is called for the first time. It could be that your script is loaded but has a syntax or runtime exception. if you add a debugger statement you’ll see the F12 debugger step into it if it’s loaded.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    For ribbon other approach is used if I'm not mistaken. That code is added on the fly and not through script reference tag so you will not see exact reference of your JS webresource.

    Again - use debugger directive in your code - www.w3schools.com/.../jsref_debugger.asp

  • Ivan Burda Profile Picture
    Ivan Burda 115 on at
    RE: Ribbon Workbench- Button on Homepage Grid doesn't fire javascript

    I've checked debugger using F12 and i can't see any javascript. On  record form i can see Custom JavaScript library but when i go to list of records i cant see any custom js

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans