javascriptdynamics-crmdynamics-365crm-ribbon-workbench

Passing CRM Parameters though Ribbon Workbench Custom Button to Javascript Functions to Get Attribute Values


I have a custom button created in Ribbon Workbench named "send email" (for short) in which the following is intended to occur: create email record-->insert email template via service-->open in modal for user.

With that being said, I have created the following Ribbon Workbench button configs:

enter image description here

As you can see, I have added the parameter that passes the execution context and the parameter that is supposed to pass the form object if I'm not mistaken.

I have written javascript which is triggered by the button. The javascript fires and works but fails when attempting to grab the record id. The following is my javascript snippet:

function ltCreateIAafterPurchaseTemplate(executionContext, item){
    alert("AFTER PURCHASE");
    
    var formContext = executionContext;
    var emailTemplateToLoad = "f22cb309-1fd9-eb11-bacb-000d3a361c51";
    var selectedItem = item[0];
    alert("selectedItem: " + selectedItem.Id);

}

Above item parameters is passed with the object data I need, and to my knowledge the statement var selectedItem = item[0] is the correct way to get it. However, I receive the following error in the alert when trying to show the id alert("selectedItem: " + selectedItem.Id); in console:

enter image description here enter image description here enter image description here

After hovering over the param passed in, it has a length of 0 stating its empty:

enter image description here


Solution

  • The first parameter is receiving execution context using PrimaryControl CRM Parameter in Ribbon command.

    The second parameter SelectedControlSelectedItemReferences will receive the expected item array when you select one or more records in grid view. Otherwise it will be null like your case.

    Select one record and the code will work.

    Learn more