Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A few things after looking that code. </p> <ol> <li><p>Make sure you are referencing all your JS attribute objects using the logical name of the attribute (ex. 'new_attributename' or 'mobilephone'). In your code you have the following attribute calls which aren't valid. <code>Xrm.Page.getAttribute("Specify Detail")</code>, <code>Xrm.Page.getAttribute("HasSubmitted")</code></p></li> <li><p>If you are adding onChange events you should use <code>attributeObj.addOnChange([function reference])</code> as outlined in the <a href="http://msdn.microsoft.com/en-us/library/gg334409.aspx#BKMK_addOnChange" rel="nofollow">SDK</a>, not <code>document.EntityScript.IsCapableOfAssistInOwnDefense_OnChange</code></p></li> </ol> <p><em><strong>EDIT</strong></em></p> <p>I was able to get the following to work. In my form customizations I added the script the account form and added <code>requireField</code> as an onload function with the parameters of <code>"donotemail", "emailaddress1"</code>. </p> <pre><code>function requireField(fieldName, fieldToRquire){ var field = Xrm.Page.getAttribute(fieldName); var fieldToRequire = Xrm.Page.getAttribute(fieldToRquire); if (!field){ alert(field + " does not exist"); return false; } if (!fieldToRequire){ alert(fieldToRquire + " does not exist"); return false; } field.setValue(null); field.addOnChange(function onChange(){ if (field.getValue() != null) { fieldToRequire.setRequiredLevel("required"); } else{ fieldToRequire.setRequiredLevel("none"); } }); } </code></pre> <p>Based on the new code you modified there are still the issues I listed above. You still aren't adding the onchange event correctly, or referencing the attributes correctly. The attribute names need to be all lowercase for it to work. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload