Search code examples
dynamics-crm-2011dynamics-crmribbon

how to add "sendemail" button in gridView of customized entity in crm


There is one customized entity named as "Add to Campaign" . Since there is no default "Email" button in sub-grid , so i placed one customized button and provided javascript to open Email form , and the Email form opens good. But now the problem is , cant able to get selected records "Email field" in "Send to field" in Email Form. so how to get selected record email to be displaced in "Email Form"


Solution

  • Open the email form with parameters:

    Xrm.Utility.openEntityForm("email", null, param);
    


    var param = {}; // passed as parameters to the new email form
    if(Xrm.Page.getAttribute("-- LogicalNameOfField --") // make sure that the field has a value
        param["-- LogicalNameOfFieldInNewEmail --"] = Xrm.Page.getAttribute("-- LogicalNameOfField --"); // passes a field value to the new form
    // This passes a lookup field as a parameter to the new form
    if(Xrm.Page.getAttribute("-- LogicalNameOfLookup --").getValue() != null) { // make sure that the lookup field is not empty or we will have a problem trying to access [0].id and [0].name
        param["-- LogicalNameofLooupFieldInEmail --"] = Xrm.Page.getAttribute("-- LogicalNameOfLookup --").getValue()[0].id;
    param["-- LogicalNameOfLookup --" + "name" (eg. "accountname")] = Xrm.Page.getAttribute("-- LogicalNameOfLookup --"].getValue()[0].name;
    Xrm.Utility.OpenEntityForm("LogicalEntityName", null, param); // open the form and pass parameters
    

    Take note of how the lookup field is passed as a parameters:

    • 2 parameters are passed for each lookup field
    • The GUID as the name of the lookup field (account if account if the name of the lookup field in the new email)
    • The name of the lookup in the source entity as a special parameter (accountname)
    • Note: there is no field called "accountname", but there is a field called "account" in this hypothetical entity