Create a FLYOUT Ribbon button and click event menu d365

 1. First add(drag and drop) the FLYOUT on form or subgrid or home

2. Add the(drag and drop)   Menu selection on list 

3. Add(drag and drop) the button in Menu selection 



4. Hide ribbon button on custom condition.

-> Set Enable rule 

call javascript custom rule



Add the java script hideshow:


function HideCopyProxybutton(formContext) {

       debugger;

       var surveytype = formContext.getAttribute("ecl_surveytype").getValue();

       if (surveytype == 806460000) {

              return true;

       } else {

              return false;

       }

}


5. Add command



On button click menu selection event 

function copyProxy(formContext, commandProperties) {

       debugger;

      

       if (commandProperties.SourceControlId.includes("Proxy1.Button")) {

              setProxyDetails(formContext,"Proxy1");

       }

       else if (commandProperties.SourceControlId.includes("Proxy2.Button")) {

              setProxyDetails(formContext, "Proxy2");

       }

       else if (commandProperties.SourceControlId.includes("Proxy3.Button")) {

              setProxyDetails(formContext, "Proxy3");

       }

       else if (commandProperties.SourceControlId.includes("Proxy4.Button")) {

              setProxyDetails(formContext, "Proxy4");

       }

}


function setProxyDetails(formContext, type) {

 

       var contactId = formContext.getAttribute("ecl_resident").getValue()[0].id.replace("{", "").replace("}", "");

       var feach = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +

              "<entity name='contact' >" +

              "<attribute name='fullname' />" +

              "<attribute name='parentcustomerid' />" +

              "<attribute name='telephone1' />" +

              "<attribute name='emailaddress1' />" +

              "<attribute name='contactid' />" +

              "<attribute name='ecl_rep3relationshiptoclient' />" +

              "<attribute name='ecl_rep3lastname' />" +

              "<attribute name='ecl_rep3email' />" +

              "<attribute name='ecl_rep3contactnumber' />" +

              "<attribute name='ecl_rep2relationshiptoclient' />" +

              "<attribute name='ecl_rep2lastname' />" +

              "<attribute name='ecl_rep2firstname' />" +

              "<attribute name='ecl_rep2email' />" +

              "<attribute name='ecl_rep2contactnumber' />" +

              "<attribute name='ecl_rep1relationshiptoclient' />" +

              "<attribute name='ecl_rep1lastname' />" +

              "<attribute name='ecl_rep1firstname' />" +

              "<attribute name='ecl_rep1email' />" +

              "<attribute name='ecl_rep1contactnumber' />" +

              "<attribute name='ecl_reptype' />" +

              "<attribute name='ecl_reprelationshiptoclient' />" +

              "<attribute name='ecl_repphone' />" +

              "<attribute name='ecl_replastname' />" +

              "<attribute name='ecl_repfirstname' />" +

              "<attribute name='ecl_repemail' />" +

              "<attribute name='ecl_repcontactnumber' />" +

              "<attribute name='ecl_rep3firstname' />" +

              "<order attribute='fullname' descending='false' />" +

              "<filter type='and'>" +

                      "<condition attribute='statecode' operator='eq' value='0' />" +

              "<condition attribute='contactid' operator='eq' uiname='Dwayne_17220 Johnson_17221' uitype='contact' value='" + contactId + "' />" +

              "</filter>" +

              "</entity>" +

              "</fetch>"

       var fetchXML = "?fetchXml=" + encodeURIComponent(feach);

       var evrVar = Xrm.WebApi.retrieveMultipleRecords('contact', fetchXML).then(function success(evrVarRec) {

              debugger;

              if (evrVarRec != null && evrVarRec.entities != null && evrVarRec.entities.length > 0) {

                      var entity = {};

                      if (type == "Proxy1") {

                      formContext.getAttribute("ecl_proxyconsent").setValue(806460000);

                      formContext.getAttribute("ecl_proxyfirstname").setValue(evrVarRec.entities[0].ecl_repfirstname);

                      formContext.getAttribute("ecl_proxylastname").setValue(evrVarRec.entities[0].ecl_replastname);

                      formContext.getAttribute("ecl_proxyrelationshiptoclient").setValue(evrVarRec.entities[0].ecl_reprelationshiptoclient);

                      formContext.getAttribute("ecl_proxytelephone").setValue(evrVarRec.entities[0].ecl_repcontactnumber);

                      formContext.getAttribute("ecl_proxyemail").setValue(evrVarRec.entities[0].ecl_repemail);

                      }

                      if (type == "Proxy2") {

                      formContext.getAttribute("ecl_proxyconsent").setValue(806460000);

                      formContext.getAttribute("ecl_proxyfirstname").setValue(evrVarRec.entities[0].ecl_rep1firstname);

                      formContext.getAttribute("ecl_proxylastname").setValue(evrVarRec.entities[0].ecl_rep1lastname);

                      formContext.getAttribute("ecl_proxyrelationshiptoclient").setValue(evrVarRec.entities[0].ecl_rep1relationshiptoclient);

                      formContext.getAttribute("ecl_proxytelephone").setValue(evrVarRec.entities[0].ecl_rep1contactnumber);

                      formContext.getAttribute("ecl_proxyemail").setValue(evrVarRec.entities[0].ecl_rep1email);

                      }

                      if (type == "Proxy3") {

                      formContext.getAttribute("ecl_proxyconsent").setValue(806460000);

                      formContext.getAttribute("ecl_proxyfirstname").setValue(evrVarRec.entities[0].ecl_rep2firstname);

                      formContext.getAttribute("ecl_proxylastname").setValue(evrVarRec.entities[0].ecl_rep2lastname);

                      formContext.getAttribute("ecl_proxyrelationshiptoclient").setValue(evrVarRec.entities[0].ecl_rep2relationshiptoclient);

                      formContext.getAttribute("ecl_proxytelephone").setValue(evrVarRec.entities[0].ecl_rep2contactnumber);

                      formContext.getAttribute("ecl_proxyemail").setValue(evrVarRec.entities[0].ecl_rep2email);

                      }

                      if (type == "Proxy4") {

                      formContext.getAttribute("ecl_proxyconsent").setValue(806460000);

                      formContext.getAttribute("ecl_proxyfirstname").setValue(evrVarRec.entities[0].ecl_rep3firstname);

                      formContext.getAttribute("ecl_proxylastname").setValue(evrVarRec.entities[0].ecl_rep3lastname);

                      formContext.getAttribute("ecl_proxyrelationshiptoclient").setValue(evrVarRec.entities[0].ecl_rep3relationshiptoclient);

                      formContext.getAttribute("ecl_proxytelephone").setValue(evrVarRec.entities[0].ecl_rep3contactnumber);

                      formContext.getAttribute("ecl_proxyemail").setValue(evrVarRec.entities[0].ecl_rep3email);

                      }

                      //Xrm.WebApi.updateRecord("contact", contactId, entity).then(function success(result) {

                      //     debugger;

                      //     console.log("status updated : " + result.id);

                      //     //formContext.data.refresh();

                      //       Xrm.Utility.openEntityForm("ecl_interview", formContext.data.entity.getId());

                      //     //quickViewRefresh();

                      //}, function (error) {

                      //     debugger;

                      //     console.log(error.message);

                      //});

              }

       });

}

 

function quickViewRefresh() {

       var quickViewControl = Xrm.Page.ui.quickForms.get("Proxy_Details");

       if (quickViewControl != null) {

              setTimeout(function () {

                      quickViewControl.refresh();

              }, 500);

       }

}


Comments

Popular posts from this blog

Power Automate compose vs variable

Update record when checkbox checked using JavaScript and save d365

Power pages custom button add in gried