I had this custom entity where the user can only fill one of three look up fields, if more than 1 are populated a error pops up. I used a custom Jscript to achieve the functionality. Triggering it on OnSave event. It is working alright when clicked save but the error is thrown twice when tried to Save&Close and Save&New.
function fnOnSave(context) { var account = Xrm.Page.getAttribute("parentaccountid") != null ? Xrm.Page.getAttribute("parentaccountid").getValue() : null; var contact = Xrm.Page.getAttribute("parentcontactid") != null ? Xrm.Page.getAttribute("parentcontactid").getValue() : null; var user = Xrm.Page.getAttribute("new_user") != null ? Xrm.Page.getAttribute("new_user").getValue() : null; var saveEvent = context.getEventArgs(); if ((account != null && contact != null) || (account != null && user != null) || (contact != null && user != null)) { alert("You can only populate one of the lead source look-up fields - Account, Contact, or User."); saveEvent.preventDefault();
return false; } }
*This post is locked for comments