Show/Hide Ribbon Button using Enable Rule

If you want to show/hide a ribbon button, but you are having problems because of the load/save events that sometimes makes the show/hide not work correctly, this is the best way I found to get the job done.

Just need to add this bit of code in the RibbonDiffXml in the extracted solution of the entity you want to add (or already have) the button, in the customization.xml file.

 <CommandDefinition Id=""> <!--button id-->
 <EnableRule Id="entity.functionName.EnableRule" />
 <DisplayRules />
 <JavaScriptFunction FunctionName="markopportunityasgo" Library="$Webresource:cst_Opportunity2013" />

 <EnableRule Id="entity.functionName.EnableRule">
 <CustomRule FunctionName="javascriptFunction" Library="$webresource:javascriptFileName">
 <CrmParameter Value="PrimaryItemIds" /> <!--get entity id-->
//Javascript function that get the entity id. If gives error, you can remove it from the funtion
function javascriptFunction(id)
 return true; //shows button

Create/Update Entity records using XrmServiceToolKit.Soap

If you want to create or update a record using the XrmServiceToolKit Soap and don’t know how to do it for all the field types, here is some code that might help you.

//Create Entity
var entity = new XrmServiceToolkit.Soap.BusinessEntity("EntityName");
entity.attributes["fieldName"] = Xrm.Page.getAttribute("fieldName").getValue();

entity.attributes['fieldName'] = { id : Xrm.Page.getAttribute('fieldName').getValue()[0].id, logicalName : Xrm.Page.getAttribute('fieldName').getValue()[0].entityType, type : 'EntityReference' };

entity.attributes["fieldName"] = Xrm.Page.getAttribute("fieldName").getValue();

entity.attributes["fieldName"] = { value: Xrm.Page.getAttribute("fieldName").getValue(), type: "OptionSetValue" };

entity.attributes["fieldName"] = { Value:"fieldName").getValue() };

entity.attributes["fieldName"] = { Value: parseFloat(eval("fieldName").getValue())) };

entity.attributes["fieldName"] = { Value: 2, type: "int"}; 

entity.attributes["fieldName"] = { Value: 1.5617, type: "double" }; 

var quoteId;
quoteId = XrmServiceToolkit.Soap.Create(entity);

//Update Entity
var updateEntity = new XrmServiceToolkit.Soap.BusinessEntity("EntityName", entityGuid);
//Lookup to update
updateEntity.attributes["fieldName"] = { id : entityGuid, logicalName : 'entityName', type : 'EntityReference' };
updateEntity.attributes["fieldName"] = { value : Value, type : 'OptionSetValue' };
updateEntity.attributes["fieldName"] = { value : Value, type : 'Money' };
updateEntity.attributes["fieldName"] = { value : true/false, type: 'boolean' };
updateEntity.attributes["fieldName"] = "Value";

updateEntity.attributes["fieldName"] = { Value: 2, type: "int"}; 

updateEntity.attributes["fieldName"] = { Value: 1.5617, type: "double" }; 

<pre>var updateResponse = XrmServiceToolkit.Soap.Update(updateEntity );