2017-09-27 2 views
0

Ich vergleiche Felder aus zwei verschiedenen Entitäten, so dass, wenn die Werte unterschiedlich sind, dann das Feld auf Formular 1, was der Feldwert auf der anderen Form ist. Das Problem ist, dass obwohl die Logik Für einige Blöcke scheint es richtig zu sein, dass es sich weigert, mit dem nächsten if/else-Block fortzufahren, es sei denn, der vorherige Wert wurde geändert.Vergleichen von Feldern aus verschiedenen Entitäten

So geht es zu den Blöcken, die den Staat und das Land ohne Probleme überprüfen, unabhängig davon, ob beide geändert werden. Wenn jedoch der Staat oder das Land nicht geändert wird (oder das Land auskommentiert wird), wird es nicht zur primären Spezialität Überprüfen Sie diese Werte. Ich bin mir nicht sicher, was ich hier vermisse. Ich habe sichergestellt, dass nichts verschachtelt ist und dass die gesamte Logik tatsächlich funktioniert.

  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["[email protected]"], 
          entityType: result["[email protected]"] 
         }]); 
       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["[email protected]"], 
           entityType: result["[email protected]"] 
          }]); 
        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["[email protected]"], 
           entityType: result["[email protected]"] 
          }]); 
       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["[email protected]"], 
           entityType: result["[email protected]"] 
          }]); 
        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["[email protected]alue"], 
           entityType: result["[email protected]ame"] 
          }]); 
      } 

      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["[email protected]alue"], 
           entityType: result["[email protected]ame"] 
          }]); 
       } 
      } 
      else { 

      } 

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

Können Sie es debuggen? Irgendwelche Fehler? –

+0

Ich war in der Lage, es zu debuggen und keine Fehler. Es war wirklich komisch, es übersprang einige der Bedingungen vollständig. Irgendwie habe ich es behoben, indem ich leere else if-Anweisungen hinzufügte, und das zwang es weiter. Macht keinen Sinn, aber ich nehme es. – amberl

Antwort

0

so um mich, um es mir leer sonst hinzuzufügen arbeiten musste, wenn die Bedingungen .Es es gezwungen, die anderen Bedingungen fortzusetzen und zu überprüfen. Das ergibt für mich keinen Sinn, aber ich konnte keinen anderen Weg finden, um es zu umgehen.

  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["[email protected]"], 
          entityType: result["[email protected]"] 
         }]); 
       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["[email protected]"], 
           entityType: result["[email protected]"] 
          }]); 
        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["[email protected]"], 
           entityType: result["[email protected]"] 
          }]); 
        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["[email protected]"], 
          entityType: result["[email protected]"] 
         }]); 
       save = true; 
      } 
      else { 

      } 
Verwandte Themen