title: Empty field causes error while saving page
body: <p>As I am new to JavaScript and Dynamic365, I need some suggestion how can I resolve error. I have the following code which shows some warning message for some specific analysis code:</p>
  <pre><code>var ShowWarning = new Object();
  
  ShowWarning.AnalysisCode = {
      onSave: (executionContext) =&gt; {
          var analysisCode = Xrm.Page.getAttribute(&quot;rf_analysisCode&quot;).getValue()[0].keyValues;
          if (analysisCode) {
              if (typeof (analysisCode) == &quot;string&quot;) {
                  var rfCode = (JSON.parse(analysisCode).rf_code).value;
              } else {
                  var rfCode = analysisCode.rf_code.value;
              }
              var analysisType = Xrm.Page.getAttribute(&quot;rf_analysistype&quot;).getValue();
              var matchingTransaction = Xrm.Page.getAttribute(&quot;rf_matchingtransaction&quot;).getValue();
              //specific analysis codes for which warning shows
              let analysisCodeDefined = [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;,];
              for (let i = 0; i &lt; analysisCodeDefined.length; i++) {
                  if (rfCode == analysisCodeDefined[i]) {
                      if (analysisType != null &amp;&amp; matchingTransaction == null) {
                           alert(&quot;Some warning message&quot;);
                           break;
                       }
                       else {
                           break;
                       }
                   }
                   else {
                       continue;
                   }
               }
           }
       }
   };
  </code></pre>
  <p>So if the analysis code field in Xrm page is empty, then when try to save, it gives the following error:</p>
  <blockquote>
  <p>TypeError: Cannot read properties of null (reading '0')
  at Object.onSave (http://CRMUrl/ShowWarning?ver=-202203:6:76)</p>
  </blockquote>
  <p>I am not sure how can I resolve this error. Because the page is supposed to save even when it does not have value in analysis code field.</p>