0

我正在比较来自两个不同实体的字段,因此如果值不同,那么表单 1 上的字段将设置为另一个表单上的字段值。问题是,尽管逻辑对于某些块来说似乎是正确的拒绝继续到下一个 if/else 块,除非之前的值改变了。

因此,无论是否更改,它都会毫无问题地检查州和国家/地区的块。但是,除非州或国家/地区被更改(或国家/地区被注释掉),否则它不会继续到主要专业来检查这些值。不知道我在这里缺少什么。我已经确保没有任何东西是嵌套的,并且所有的逻辑都确实有效。

            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");
4

1 回答 1

0

所以为了让我让它工作,我必须添加空 else if 条件。它迫使它继续并检查其他条件。这对我来说毫无意义,但无法找到另一种解决方法。

            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.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"]
                      }]);
                save = true;
            }
            else if (getFieldValue("hc_stateid") == null && result["_hc_state_value"] == null) {
                //this is needed otherwise it does not continue to check conditons
            }

            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);
                    save = true;
                }
                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"]
                            }]);
                    save = true; 
                }
            }
            else {

            }




            if (getFieldValue("hc_countryid") == null && result["_hc_country_value"] != null || getFieldValue("hc_countryid") != null && result["_hc_country_value"] == null) {
                if (result["_hc_country_value"] == null) {
                    Xrm.Page.getAttribute("hc_countryid").setValue(null);
                    save = true;
                }
                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"]
                            }]);
                    save = true; 
                }
            }
            else if (getFieldValue("hc_countryid") == null && result["_hc_country_value"] == null) {
                //this is needed otherwise it does not continue to check conditons
            }

            else if (getFieldValue("hc_countryid")[0].id.replace("{", "").replace("}", "").toString().toLowerCase() != result["_hc_country_value"]) {

                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"]
                        }]);
                save = true; 
            }
            else {

            }
于 2017-10-02T12:20:04.523 回答