locked
Compare a Field data value with curent user name RRS feed

  • Question

  • Hey guys I have 2 field (requester Name AND Requester Status) in Crm 2011 Custom form

    I want when a Requester Name And owner Form(login user name) is not the same then Requester Status is disable.

    How Do i do .Step by step  Please

    thank a lot

    Wednesday, November 20, 2013 5:16 AM

Answers

  • Here is some JavaScript that should achieve your requirements. Just change the field names to match the ones in your custom form. You can wire this function to the onload and onchange event of the owner and requester fields.

    Hope this helps.

    function requesterCheck() {
        var owner = Xrm.Page.getAttribute("ownerid");
        var requester = Xrm.Page.getAttribute("new_requesterid");
    
        if (owner.getValue() != null && requester.getValue() != null) { // Check that Owner and Requester have a Value
            if (owner.getValue()[0].id === requester.getValue()[0].id)  // Then compare if they have the same GUID
                Xrm.Page.ui.controls.get("new_requesterstatus").setDisabled(true); // Disable the Requester Status field if same
            else
                Xrm.Page.ui.controls.get("new_requesterstatus").setDisabled(false); // else enable the Requester Status field
        }
    }


    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]

    • Marked as answer by Sadeghkhan Wednesday, November 20, 2013 6:43 AM
    Wednesday, November 20, 2013 5:54 AM

All replies

  • Here is some JavaScript that should achieve your requirements. Just change the field names to match the ones in your custom form. You can wire this function to the onload and onchange event of the owner and requester fields.

    Hope this helps.

    function requesterCheck() {
        var owner = Xrm.Page.getAttribute("ownerid");
        var requester = Xrm.Page.getAttribute("new_requesterid");
    
        if (owner.getValue() != null && requester.getValue() != null) { // Check that Owner and Requester have a Value
            if (owner.getValue()[0].id === requester.getValue()[0].id)  // Then compare if they have the same GUID
                Xrm.Page.ui.controls.get("new_requesterstatus").setDisabled(true); // Disable the Requester Status field if same
            else
                Xrm.Page.ui.controls.get("new_requesterstatus").setDisabled(false); // else enable the Requester Status field
        }
    }


    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]

    • Marked as answer by Sadeghkhan Wednesday, November 20, 2013 6:43 AM
    Wednesday, November 20, 2013 5:54 AM
  • Eric UNG [Senior Analyst Programmer :: Sydney, Australia]    very very help full

    Thank U :-)

    Wednesday, November 20, 2013 6:45 AM