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);
         
            }
        }
    }

CRM 2013 Bulk Edit Form - to enable Scripts



Similar to MSCRM 4, events won't fire by default in CRM 2013.  Also, any field with an onchange event will be rendered disabled!  There is a nasty way to go about it enabling these fields or allowing your scripts to execute.


Export the entity you wish to enable scripted bulk edits for in an unmanaged solution.  Un-zip the package and open up customizations.xml.


To allow an event, follow the below xpath which will take you to the events for a form.  If you have multiple forms, you may repeat for each form (TBD:  not sure if these appear under systemform or not).  If you're enabling for multiple entities, you may repeat for each entity.


\\ImportExportXml\Entities\Entity[@name='new_entityname']\FormXml\forms[@type=’main’]\systemform\form\events\event[@name=’onload’]



This xpath takes us to the onload event for the main form of the new_entityname entity.  To this node, we need to add the BehaviorInBulkEditForm attribute.


<event name="onload" application="false" active="true" BehaviorInBulkEditForm="Enabled">


Enabled - If this is an event related to a field (onchange), then the field will be enabled.  The script will run.

EnabledButNoRender - If this is an event related to a field (onchange), then the field will be enabled.  However, the script will not run.
Disabled - (default) If this is an event related to a field, then that field will be disabled.  The script will not run.

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...