Monday, 7 December 2015

CRM 2013 Role Based optionset Values





if (!XrmServiceToolkit.Soap.IsCurrentUserRole("System Administrator")) {

        var xrmPage = Xrm.Page;
        var pickListField = xrmPage.getAttribute("new_passorfail");
        var StatusValue = xrmPage.getAttribute("new_passorfail").getValue();
        var options = pickListField.getOptions();
        for (var i = 0; i < options.length; i++) {
            if (options[i].value != StatusValue) {
                Xrm.Page.getControl("new_passorfail").removeOption(options[i].value);
            }
        }
        //save all options
        if (!window.wsOptions) {
            window.wsOptions = {};
            wsOptions.pass = pickListField.getOption(920170000);
            wsOptions.fail = pickListField.getOption(920170001);
            wsOptions.waiting = pickListField.getOption(920170002);
            wsOptions.retest = pickListField.getOption(920170003);
            wsOptions.invalid = pickListField.getOption(920170004);
            wsOptions.spec = pickListField.getOption(920170005);
            wsOptions.fixed = pickListField.getOption(920170006);
        }

        if (XrmServiceToolkit.Soap.IsCurrentUserRole("Developer")) {

            if (wsOptions.spec.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.spec);
            if (wsOptions.invalid.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.invalid);
            if (wsOptions.retest.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.retest);
            if (wsOptions.fixed.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.fixed);
        }
        if (XrmServiceToolkit.Soap.IsCurrentUserRole("Tester")) {
            if (wsOptions.pass.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.pass);
            if (wsOptions.fail.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.fail);
            if (wsOptions.waiting.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.waiting);
         
            }
        }
    }

No comments:

Post a Comment

Hide New... button on lookup controls in model-driven apps

  The 'New ...' button is shown upon opening the lookup search dialog whenever the logged in user has at least user create privileg...