mercredi 27 septembre 2017

comparing fields from different entities

So I am comparing fields from two different Entities,so that if the values are different then the field on form 1 gets set to what the field value is on the other form.The problem is that although the logic seems right for some of the blocks it refuses to continue to the next if/else block unless the previous value changed.

So it goes to the blocks that check the state and country with no problems regardless if either are changed.However unless the state or country is changed(or country is commented out) it does not continue to the primary specialty to get check those values. Not sure what I'm missing here. I've made sure that nothing is nested and that all the logic actually works.

            Xrm.Utility.alertDialog("about to check state");
            if (getFieldValue("hc_stateid") == null && result["_hc_state_value"] != null) {// checling if value is null on tni becacuse the else if wouldnt execute b/c no id
                Xrm.Utility.alertDialog("its null");
                Xrm.Page.getAttribute("hc_stateid").
                  setValue([
                      {
                          id: result["_hc_state_value"],
                          name: result["_hc_state_value@OData.Community.Display.V1.FormattedValue"],
                          entityType: result["_hc_state_value@Microsoft.Dynamics.CRM.lookuplogicalname"]
                      }]);
                Xrm.Utility.alertDialog("state changes");
            }

            else if (result["_hc_state_value"] != getFieldValue("hc_stateid")[0].id.replace("{", "").replace("}", "").toString().toLowerCase()) {//tni has a value


                if (result["_hc_state_value"] == null) {
                    Xrm.Page.getAttribute("hc_stateid").setValue(null);
                }
                else {


                    Xrm.Page.getAttribute("hc_stateid").
                        setValue([
                            {
                                id: result["_hc_state_value"],
                                name: result["_hc_state_value@OData.Community.Display.V1.FormattedValue"],
                                entityType: result["_hc_state_value@Microsoft.Dynamics.CRM.lookuplogicalname"]
                            }]);
                    Xrm.Utility.alertDialog("state changes");
                }
            }


            Xrm.Utility.alertDialog("about to check country");
            /*if (getFieldValue("hc_countryid") == null && result["_hc_country_value"] != null)
            {
                Xrm.Page.getAttribute("hc_countryid").
                        setValue([
                            {
                                id: result["_hc_country_value"],
                                name: result["_hc_country_value@OData.Community.Display.V1.FormattedValue"],
                                entityType: result["_hc_country_value@Microsoft.Dynamics.CRM.lookuplogicalname"]
                            }]);
                Xrm.Utility.alertDialog("country changed");

            }
            else if (result["_hc_country_value"] != getFieldValue("hc_countryid")[0].id.replace("{", "").replace("}", "").toString().toLowerCase()) {
                if (result["_hc_country_value"] == null) {
                    Xrm.Page.getAttribute("hc_countryid").setValue(null);
                }
                else {
                    Xrm.Page.getAttribute("hc_countryid").
                        setValue([
                            {
                                id: result["_hc_country_value"],
                                name: result["_hc_country_value@OData.Community.Display.V1.FormattedValue"],
                                entityType: result["_hc_country_value@Microsoft.Dynamics.CRM.lookuplogicalname"]
                            }]);
                    Xrm.Utility.alertDialog("country changed");
                }
            } */

            Xrm.Utility.alertDialog("about to check prim spec");
            Xrm.Utility.alertDialog("prim specialty: " + (result["_hc_primaryspecialty_value"] != getFieldValue("hc_primaryspecialtyid")[0].id.replace("{", "").replace("}", "").toString().toLowerCase()).toString());
            if (getFieldValue("hc_primaryspecialtyid") == null && result["_hc_primaryspecialty_value"] != null) {
                Xrm.Page.getAttribute("hc_primaryspecialtyid").
                      setValue([
                          {
                              id: result["_hc_primaryspecialty_value"],
                              name: result["_hc_primaryspecialty_value@OData.Community.Display.V1.FormattedValue"],
                              entityType: result["_hc_primaryspecialty_value@Microsoft.Dynamics.CRM.lookuplogicalname"]
                          }]);
            }

            else if (result["_hc_primaryspecialty_value"] != getFieldValue("hc_primaryspecialtyid")[0].id.replace("{", "").replace("}", "").toString().toLowerCase()) {
                Xrm.Utility.alertDialog("inside else if");
                if (result["_hc_primaryspecialty_value"] == null) {
                    Xrm.Page.getAttribute("hc_primaryspecialtyid").setValue(null);
                }
                else {
                    Xrm.Utility.alertDialog("prime spec");
                    Xrm.Page.getAttribute("hc_primaryspecialtyid").
                        setValue([
                            {
                                id: result["_hc_primaryspecialty_value"],
                                name: result["_hc_primaryspecialty_value@OData.Community.Display.V1.FormattedValue"],
                                entityType: result["_hc_primaryspecialty_value@Microsoft.Dynamics.CRM.lookuplogicalname"]
                            }]);
                }
            }
            else {

            }

            Xrm.Utility.alertDialog("after prim spec");

Aucun commentaire:

Enregistrer un commentaire