javascriptdynamics-crmdynamics-crm-2015

XRM JavaScript : Enable/ and Disable user


I have tried to make Enable/Disable user with clear term date in systemuser entity form by using Javascript and written below code.

var ClearTermDate= function () {
        var termDate = Xrm.Page.getAttribute("new_termdate");
        if (termDate!= null) {
            termDate.setValue(null);
        }
        Xrm.Page.getAttribute("isdisabled").setValue(false);
        Xrm.Page.data.entity.save();
    };

isdisabled attribute is not updating. Please suggest code or alternative solution.


Solution

  • Bingo! isdisabled is Read-only property in systemuser entity per MSDN. You cannot do this in JS directly like you're doing.

    You have to follow one of these:

    1. If you are in 2015 - use soap call to do SetStateRequest in JS
    2. If you have 2015 update 1 - use web api to do SetStateRequest in JS
    3. Or setup a plugin on update of Term date to disable user