My client wants to change the grid view color based on the contact entity address type value is "Ship To".
So i added a button in the contact entity "<ribbondiffxml>", but i didn't make it display, you can see there is no command in the "<displayrules>". I added new <customrule> to call the javascript("dns_contact") function ("BackGroundColorGrid") to change the color.
Make sure you added jquery in your webresources.
Same way you can change color for the grid.
javascript code>
Same way you can change color for the grid.
<Entity>
<Name LocalizedName="contact" OriginalName="contact">contact</Name>
<ObjectTypeCode/>
<EntityInfo/>
<FormXml/>
<SavedQueries/>
<RibbonDiffXml>
<CustomActions>
<CustomAction Id="dns.McTools.HomePageGrid.contact.BackGroundColor.Button.CustomAction" Location="Mscrm.HomepageGrid.contact.MainTab.Management.Controls._children" Sequence="15">
<CommandUIDefinition>
<Button Alt="$LocLabels:McTools.HomePageGrid.contact.BackGroundColor.Button.Alt" Command="BackGroundColorView.Command" CommandType="General" Description="BackGroundColor" Id="McTools.HomePageGrid.contact.BackGroundColor.Button" Image32by32="" Image16by16="" LabelText="" Sequence="15" TemplateAlias="o1" ToolTipTitle="" ToolTipDescription="" />
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
</Templates>
<CommandDefinitions>
<CommandDefinition Id="BackGroundColorView.Command">
<EnableRules>
<EnableRule Id="dns.contact.EnableRule0.EnableRule" />
</EnableRules>
<DisplayRules />
<Actions />
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules />
<EnableRules>
<EnableRule Id="dns.contact.EnableRule0.EnableRule">
<CustomRule FunctionName="BackGroundColorGrid" Library="$webresource:dns_contact" Default="false" InvertResult="false">
<CrmParameter Value="SelectedControlAllItemReferences" />
<CrmParameter Value="SelectedControl" />
</CustomRule>
</EnableRule>
</EnableRules>
</RuleDefinitions>
<LocLabels/>
</RibbonDiffXml>
</Entity>
<Name LocalizedName="contact" OriginalName="contact">contact</Name>
<ObjectTypeCode/>
<EntityInfo/>
<FormXml/>
<SavedQueries/>
<RibbonDiffXml>
<CustomActions>
<CustomAction Id="dns.McTools.HomePageGrid.contact.BackGroundColor.Button.CustomAction" Location="Mscrm.HomepageGrid.contact.MainTab.Management.Controls._children" Sequence="15">
<CommandUIDefinition>
<Button Alt="$LocLabels:McTools.HomePageGrid.contact.BackGroundColor.Button.Alt" Command="BackGroundColorView.Command" CommandType="General" Description="BackGroundColor" Id="McTools.HomePageGrid.contact.BackGroundColor.Button" Image32by32="" Image16by16="" LabelText="" Sequence="15" TemplateAlias="o1" ToolTipTitle="" ToolTipDescription="" />
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
</Templates>
<CommandDefinitions>
<CommandDefinition Id="BackGroundColorView.Command">
<EnableRules>
<EnableRule Id="dns.contact.EnableRule0.EnableRule" />
</EnableRules>
<DisplayRules />
<Actions />
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules />
<EnableRules>
<EnableRule Id="dns.contact.EnableRule0.EnableRule">
<CustomRule FunctionName="BackGroundColorGrid" Library="$webresource:dns_contact" Default="false" InvertResult="false">
<CrmParameter Value="SelectedControlAllItemReferences" />
<CrmParameter Value="SelectedControl" />
</CustomRule>
</EnableRule>
</EnableRules>
</RuleDefinitions>
<LocLabels/>
</RibbonDiffXml>
</Entity>
javascript code>
BackGroundColorGrid (items, grid) {
try {
if (items) {
//var index = $("#gridBodyTable").find("col[name=address1_addresstypecode]").index();
//if (index != -1) {
for (var i = 0; i < items.length; i++) {
var id = items[i].Id;
$(grid._element).find("tr[oid='" + id + "']").each(function () {
var theTr = $(this);
//console.log(i+ " - " + theTr.children('td').length)
//if (theTr.find("td").slice(index, index+1).text().toLowerCase().indexOf("Ship To") >= 0) {
theTr.find("td").css("background-color", "#FFFFFF");
//}
});
}
//}
}
}
catch (e) {
alert(e.description);
}
}
try {
if (items) {
//var index = $("#gridBodyTable").find("col[name=address1_addresstypecode]").index();
//if (index != -1) {
for (var i = 0; i < items.length; i++) {
var id = items[i].Id;
$(grid._element).find("tr[oid='" + id + "']").each(function () {
var theTr = $(this);
//console.log(i+ " - " + theTr.children('td').length)
//if (theTr.find("td").slice(index, index+1).text().toLowerCase().indexOf("Ship To") >= 0) {
theTr.find("td").css("background-color", "#FFFFFF");
//}
});
}
//}
}
}
catch (e) {
alert(e.description);
}
}
Reference
MS Dynamics CRM 2011 - EnableRule, ValueRule, OrRule & CustomRule in Ribbon Customizations
MS Dynamics CRM 2011 - Ribbon Drop Down Menu
Customize the CRM Ribbon
No comments:
Post a Comment