In general, create a new solution for the custom command bar and ribbon area, I'm here to create a new ribboneditor solution, and then add the entities you want to modify.
650) this.width=650; "src=" http://img0.ph.126.net/8Yxhz5QIH3vJznCw00bu-A==/2096425626641134401.jpg "/>
I am here to select the quote entity and then click the OK button.
650) this.width=650; "src=" http://img2.ph.126.net/8XxeuyWA1V-druRfhNAM_g==/1936829314846368296.jpg "/>
Click the custom icon on the CRM > Settings > Solutions page.
650) this.width=650; "src=" http://img2.ph.126.net/Fh0kSuV5vPNScJ31e55Vvg==/3069766096024313246.jpg "/>
Select the solution that you created earlier, and then click the OK button.
650) this.width=650; "src=" http://img0.ph.126.net/NunfDX3VG9c2ybbmelWmug==/2757328871875521621.jpg "/>
Make sure the selected tab is command Bar, because the entity I want to modify here is an updated entity in the Dynamics CRM 2013 release. Select the entity you want to modify in entities, and the above section will be updated to the command bar of the entity you selected.
650) this.width=650; "src=" http://img1.ph.126.net/TzNwCmn3sd1wuGTo0N2gDQ==/143270763245975329.jpg "/>
Then according to the area of the command bar you want to change, select the appropriate command button, I am here to modify the form command bar, so I choose the following, select the Thing form the Active quote button.
650) this.width=650; "src=" http://img2.ph.126.net/9i7fwr3EKxx41NRmaK7m4A==/1914874266663169778.jpg "/>
Right-click the command button I want to modify and select the Customize commands menu item.
650) this.width=650; "src=" http://img2.ph.126.net/Q0dtdK9wu8hjV59PdbQEpg==/2757328871875521623.jpg "/>
Then you can see some changes, as below, which are some of the properties of this button.
650) this.width=650; "src=" http://img2.ph.126.net/QWTurhOen7D615E6-4Vepw==/3043307448295702283.jpg "/>
The best way to do this is to add a diplay rule to hide this button according to the conditions, as described here. Right-click the Display Rules and select Add new to this menu item, as follows.
650) this.width=650; "src=" http://img2.ph.126.net/RZhcEOuz8RkGsm9y1fPZSw==/3005589801416784728.jpg "/>
You will see the Display rules more than one row of records, right click, select Add Rule.
650) this.width=650; "src=" http://img1.ph.126.net/OOSZfIkHoYOm0mPQ6SRqDQ==/1489284101876287360.jpg "/>
The pop-up window is as follows, but we're going to use the Enable rule to determine if we have a role permission based on our custom JavaScript, and there's no type we want.
650) this.width=650; "src=" http://img0.ph.126.net/3QaMDB2SD3B5soUhdowDWg==/6598227552402448938.jpg "/>
Delete the previously established display rule, which we use to enable rule. You can see that the Enable rule is already available, right-click on the existing enable rule and select the ADD new menu item.
650) this.width=650; "src=" http://img2.ph.126.net/nAqyZIBw1ZO0JvJp1w7UJw==/143270763245975330.jpg "/>
The optional type here is somewhat different from the preceding display rule, where I choose Custom Javascript rule and click the OK button.
650) this.width=650; "src=" http://img0.ph.126.net/b879SZTWglwo8T2YGYEsXA==/823314306979136253.jpg "/>
will have a Custom rule node, select it, and set the property on the right below.
650) this.width=650; "src=" http://img2.ph.126.net/en79b1nf_oWXto5DWVyxgQ==/6597150031007610968.jpg "/>
Note that the Web Resource selected in the library (I'm new_/test.js here) must first be uploaded to this solution, and the function (here is userinsalesmanagerrole) must be defined first.
Then save and publish, such as.
650) this.width=650; "src=" http://img0.ph.126.net/F9cmoFYhk83SPh9CjkFmFg==/680325018809955060.jpg "/>
650) this.width=650; "src=" http://img0.ph.126.net/yI5QT5gH3t4DhLYWu2l_Ag==/1403434233979646484.jpg "/>
Finally I went to the test and found that the quote button was not activated.
650) this.width=650; "src=" http://img0.ph.126.net/RAxUnqRyIJ2BHo9kOSfCZQ==/1344605963764868307.jpg "/>
I can see this button by changing the account that has this character.
650) this.width=650; "src=" http://img0.ph.126.net/gHXH0IhL_U8bYqTXK5Y9tQ==/3227955033018082329.jpg "/>
The code used is as follows:
Function guidsareequal (GUID1,&NBSP;GUID2) {var isEqual = false;if (guid1 == null | | guid2 == null) {isequal = false;} Else {isequal = guid1.replace (/[{}]/g, ""). toLowerCase () == guid2.replace (/[{}]/ g, ""). toLowerCase ();} Return isequal;} Function hasrole (RoleName) {var serverurl = xrm.page.context.getclienturl ();var odataendpointurl = serverurl + "/xrmservices/2011/organizationdata.svc/"; oDataEndpointUrl += "Roleset $select =roleid& $filter =name eq '" + encodeuricomponent (roleName ) + "'"; Var service = new xmlhttprequest ();if (service != null) {service.open ("GET", odataendpointurl, false); Service.setrequestheader ("Accept", " Application/json "), Service.setrequestheader (" Content-type ", " Application/json; charset=utf-8 "); serviCe.send (null); Var requestresults = eval (' (' + service.responseText + ') '). D ;if (requestresults != null && requestresults.results.length >= 1) {var currentuserroles = xrm.page.context.getuserroles ();for (var j = 0; j < requestresults.results.length; j++) {var RoleId = REQUESTRESULTS.RESULTS[J]. roleid;for (var i = 0; i < currentuserroles.length; i++) { userroleid = currentuserroles[i];if (Guidsareequal (Userroleid, roleid)) {return true;}}}} Return false;} function userinsalesmanagerrole () {return hasrole (' Sales Manager ');}
As you can see, using the Ribbon Workbench custom buttons is an addition to the following XML, which can be referred to as the SDK.
<RuleDefinitions> <tabdisplayrules/> <displayrules/> <EnableRules> <enablerule id= " Mscrm.quoteisindraftstate "> <formstaterule state=" Disabled "invertresult=" true "/> <formstaterule State= "Create" invertresult= "true"/> <customrule functionname= "userinsalesmanagerrole" library= "$webresource: new_/ Test.js "default=" false "invertresult=" false "/> </EnableRule> </EnableRules> </ruledefinitions > <loclabels/> </RibbonDiffXml>
650) this.width=650; "src=" http://img1.ph.126.net/mqzWqU1rpuQ9P0PMDFBDug==/2690900777371804732.jpg "/>
Remember not to make a low-level error: If your Web resource is directly edited and uploaded by Notepad, remember to choose the encoding for UTF-8 instead of the default ASCII, which may include Chinese in your code.
October 6, 2015 add: generally with a special JS file to save the Ribbon area (command bar) to use the Java Script Type Web resources, such as this JS file I generally named New_/common/ribbonscript.js, I did not do this blog post, we do not learn. Because in the course of debug JavaScript, the Java script type Web resource used, such as new_/common/ribbonscript.js, will not be found when the browser presses F12 for debugging. , if you and the entity use the main JS file is one, debugging JS will bring trouble. Another notable point is that the Enable rule executes two times, one time before the form is loaded, and this time the value of the field in the form is not available, and if your JS code involves getting the error, my suggestion is to put all the code in the try Catch block. When you catch an exception, do not eject the prompt, do not process directly, return FALSE. Here is an example of the following:
//Determine if the owner of the record equals the current user
function Checkownerequalscurrentuser() {
Try {
varuserId= Xrm.Page.Context.getUserId();
varowner= Xrm.Page.getattribute("ownerID").GetValue();
varownerID=owner[0].ID;
if (userId.toLowerCase() ==ownerID.toLowerCase()) {
return true;
}
Else {
return false;
}
}
Catch (ex) {
//xrm.utility.alertdialog (ex.message);//To comment out this line of code, otherwise it will pop up an error message
return false;
}
}
CRM client program Development: Customizing the availability of System standard buttons