CRM2011 Javascript for Required field

Set Required field based on field value selection

//if  the anks is abc, xyz, zzzz or qqqq then the  contract number field is required

function onanks() {
    if (Xrm.Page.getAttribute("new_anks").getValue() != null) {
        var currentVal = Xrm.Page.getAttribute("new_anks").getValue();
        if (currentVal != null) {
            if (currentVal == 3 || currentVal == 4 || currentVal == 5 || currentVal == 6) {
                Xrm.Page.getAttribute("new_existingcontractnum").setRequiredLevel("required");
                Xrm.Page.getAttribute("new_original_margin").setRequiredLevel("required");
                Xrm.Page.getAttribute("new_incremental_margin").setRequiredLevel("required");
                Xrm.Page.getAttribute("new_original_broker_fee").setRequiredLevel("required");
                Xrm.Page.getAttribute("new_incremental_broker_fee").setRequiredLevel("required");
            }
            else {
                Xrm.Page.getAttribute("new_existingcontractnum").setRequiredLevel("none");
                Xrm.Page.getAttribute("new_original_margin").setRequiredLevel("none");
                Xrm.Page.getAttribute("new_incremental_margin").setRequiredLevel("none");
                Xrm.Page.getAttribute("new_original_broker_fee").setRequiredLevel("none");
                Xrm.Page.getAttribute("new_incremental_broker_fee").setRequiredLevel("none");
            }
        }
    }

}

Post a Comment

0 Comments