Archive

Archive for the ‘Ribbon’ Category

Disabling Assign ribbon button based on custom logic using jscript CRM 2011

In one of my requirement, I have to enable/disable “Assign” button on “Account” form based on one of my option set value (i.e.,accountcategorycode)

Assign Button On Account Form

Assign Button On Account Form

I followed below steps to achieve the requirement

  • Get the Account “Assign” ribbon button details from “sdk\resources\exportedribbonxml\ accountribbon.xml” file from the SDK
    • Open a note pad and copy below two nodes for reference
    • Copy <Button Id=”Mscrm.Form.account.Assign”> tag
    • Copy <CommandDefinition Id=”Mscrm.AssignPrimaryRecord”> tag
  • Create a new jscript webresoure “new_Account_Ribbon” with function “enableAssignButton” and publish
    • If the function returns true the “Assign” button gets enabled else disabled
    • Define your own custom logic (Refer my custom logic below)

function enableAssignButton() {

try {

var fldCategory = Xrm.Page.data.entity.attributes.get(“accountcategorycode”);

if (fldCategory && fldCategory.getValue()) {

if (fldCategory.getValue() == 100000007) {

return true;

}

}

return false;

} catch (e) {

alert(“Error while enabling Assign button: ” + e.description);

}

}

  • Create a new solution and include “Account” entity and export as Unmanaged solution
  • Extract the zip folder and open “customizations.xml” using visual studio
  • Navigate to <RibbonDiffXml> node
  • Replace with below node (Refer comments to understand)

<RibbonDiffXml>

<CustomActions>

<!– Location will be ID of the Button–>

<CustomAction Location=”Mscrm.Form.account.Assign” Id=”Form.account.DisableAssign”>

<CommandUIDefinition>

<!– Paste the Assign button tag which you copied to notepad–>

<Button Id=”Mscrm.Form.account.Assign” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign”

ToolTipDescription=”$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Assign”

Command=”Mscrm.AssignPrimaryRecord” Sequence=”33″

LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign”

Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign” Image16by16=”/_imgs/ribbon/Assign_16.png” Image32by32=”/_imgs/ribbon/Assign_32.png” TemplateAlias=”o1″ />

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

<RibbonTemplates Id=”Mscrm.Templates”></RibbonTemplates>

</Templates>

<CommandDefinitions>

<!– Paste the Assign button Command Definition which you copied to notepad –>

<CommandDefinition Id=”Mscrm.AssignPrimaryRecord”>

<EnableRules>

<EnableRule Id=”Mscrm.FormStateNotNew” />

<EnableRule Id=”Mscrm.AssignPrimaryPermission” />

<EnableRule Id=”Mscrm.NotOffline” />

<!– Add new Enable Rule–>

<EnableRule Id=”Form.account.AssignButton.EnableRule”/>

</EnableRules>

<DisplayRules>

<DisplayRule Id=”Mscrm.AssignPrimaryPermission” />

<DisplayRule Id=”Mscrm.NotClosedActivity” />

</DisplayRules>

<Actions>

<JavaScriptFunction FunctionName=”assignObject” Library=”/_static/_forms/form.js”>

<CrmParameter Value=”PrimaryEntityTypeCode” />

</JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules />

<DisplayRules />

<EnableRules>

<!– Define Enable Rule–>

<EnableRule Id=”Form.account.AssignButton.EnableRule”>

<CustomRule Library=”$webresource:new_Account_Ribbon” FunctionName=”enableAssignButton“>

</CustomRule>

</EnableRule>

</EnableRules>

</RuleDefinitions>

<LocLabels />

</RibbonDiffXml>

🙂

Rename out of the box associated view ribbon buttons in CRM 2011

Hi,

When we have relationship between two entities, the child entity link add to the left navigation of parent.

For example,

  • “Contacts” link add to the left navigation of “Accounts”
Contacts Associated View In Account

Contacts Associated View In Account

The view we call it as “Associate View” and it contains buttons with below naming convention

  • “Add {Display name of child}” (i.e., “Add Contact” in above screen)
  • “Add Existing {Display name of child}” (i.e., “Add Existing Contact” in above screen)

To rename the “Add & Add existing” buttons below are the steps

  • Create a new solution
  • Add child entity (i.e., Contact) in above example
  • Export & Save solution in local folder
  • Extract folder and open “Customizations.XML” in Visual Studio
  • Find <RibbonDiffXml><CustomActions> node
  • Add below XML

          <CustomAction Id=”Mscrm.SubGrid.{Entity Name}.AddNewStandard.CustomAction” Location=”Mscrm.SubGrid.{Entity Name}.AddNewStandard” Sequence=”210″>

<CommandUIDefinition>

<!–New Button Id – AddNewStandard; Existing Button Id – AddExistingStandard–>

<Button Id=”Mscrm.SubGrid.{Entity Name}.AddNewStandard

Command=”Mscrm.AddNewRecordFromSubGridStandard”

Sequence=”20″

LabelText=”My Custom Text

Alt=”My Custom Text

Image16by16=”/_imgs/ribbon/NewRecord_16.png” Image32by32=”/_imgs/ribbon/newrecord32.png”

TemplateAlias=”o1″ ToolTipTitle=”Add New Contact”

ToolTipDescription=”$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipDescription” />

</CommandUIDefinition>

</CustomAction>

  • Save, zip & Export solution

🙂

 

Opening a report using ribbon button in CRM 2011

April 10, 2012 5 comments

Hi,

To open the Report :-

  • We need report GUID and report associated entity record GUID
  • Get report GUID by using ‘Report Name’ using ‘retrieveMultiple’ function
  • Prepare URl and open new window

Below are the functions

function openReport (reportName) {

var oDataSetName = “ReportSet”;

var columns = “ReportId”;

var filter = “Name eq ‘” + reportName + “‘”;

retrieveMultiple(oDataSetName, columns, filter, onSuccess);

currReportName = reportName;

}

var currReportName;

function onSuccess (data, textStatus, XmlHttpRequest) {

var serverUrl = Xrm.Page.context.getServerUrl();

if (data && data.length > 0) {

var serverUrl = Xrm.Page.context.getServerUrl();

var id = Xrm.Page.data.entity.getId();

var etc = Xrm.Page.context.getQueryStringParameters().etc;

var callReportId = id.replace(‘{‘, ”).replace(‘}’, ”);

var reportId = data[0].ReportId.replace(‘{‘, ”).replace(‘}’, ”);

var url = serverUrl + “/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=” + currReportName + “.rdl&id=%7b” + reportId + “%7d&records=%7b” + callReportId + “%7d&recordstype=” + etc;

window.open(url, “reportwindow”, “resizable=1,width=950,height=700”);

}

}

function retrieveMultiple(odataSetName, select, filter, successCallback) {

var serverUrl = Xrm.Page.context.getServerUrl();

var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;

var odataUri = serverUrl + ODATA_ENDPOINT + “/” + odataSetName + “?”;

if (select) {

odataUri += “$select=” + select + “&”;

}

if (filter) {

odataUri += “$filter=” + filter;

}

$.ajax({

type: “GET”,

contentType: “application/json; charset=utf-8”,

datatype: “json”,

url: odataUri,

beforeSend: function (XMLHttpRequest) {

XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);

},

success: function (data, textStatus, XmlHttpRequest) {

if (successCallback) {

if (data && data.d && data.d.results) {

successCallback(data.d.results, textStatus, XmlHttpRequest);

}

else if (data && data.d) {

successCallback(data.d, textStatus, XmlHttpRequest);

}

else {

successCallback(data, textStatus, XmlHttpRequest);

}

}

},

error: function (XmlHttpRequest, textStatus, errorThrown) {

if (XmlHttpRequest && XmlHttpRequest.responseText) {

alert(“Error while retrieval ; Error – ” + XmlHttpRequest.responseText);

}

}

});

}

  • Create a new .Jscript  file and copy above functions
  • Replace double quotes & single quote symbols with keyboard symbols
  • Add the .jscript as web resource
  • Add “json” & “jquery” helper scripts as web resources

How Do I call these methods :-

  • Assume you have a report named “My Account Report” associated (i.e., Related Record Types) to “Account” entity
  • Place a ribbon button on account entity form
  • Call openReport(“My Account Report”) function from ribbon button (How to call function from ribbon button)

Hope it helps 🙂

Adding New Tab & Group & Buttons to CRM form Ribbon

March 17, 2012 3 comments

Hi,

Here are the steps to add new Tab, Group and Buttons to the ‘Contact’ form and call .jscript functions on button click.

Ribbon Customizations - Contact Form

Ribbon Customizations - Contact Form

Steps :-

  • Create a new .jscript file “contact.js” with below functions

function fnA() {

alert(“Button \”A\” clicked!!!”);

}

function fnB() {

alert(“Button \”B\” clicked!!!”);

}

  • Open CRM application and add the “contact.js” as web resource
  • Create a new unmanaged solution and add “Contact” entity and “contact.js” web resource
  • Export the solution to the local folder
  • Unzip the folder
  • Open “customizations.xml” in Visual studio
  • Navigate to “<Entities><Entity>Contact”
  • Go to  <RibbonDiffXml> node and replace with below XML

 

<RibbonDiffXml>

<CustomActions>

<CustomAction Id=”Sample.Form.contact.CustomTab.CustomAction” Location=”Mscrm.Tabs._children” Sequence=”40″>

<CommandUIDefinition>

<Tab Id=”Sample.Form.contact.CustomTab” Command=”Sample.Form.contact.CustomTab”

Title=”$LocLabels:Sample.contact.CustomTab.Title”

Description=”$LocLabels:Sample.contact.CustomTab.Description” Sequence=”40″>

<Scaling Id=”Sample.Form.contact.CustomTab.Scaling”>

<MaxSize Id=”Sample.Form.contact.CustomTab.CustomGroup.MaxSize”

GroupId=”Sample.Form.contact.CustomTab.CustomGroup” Sequence=”10″ Size=”LargeMedium” />

</Scaling>

<Groups Id=”Sample.Form.contact.CustomTab.Groups”>

<Group Id=”Sample.Form.contact.CustomTab.CustomGroup”

Command=”Sample.Form.contact.CustomGroup”

Sequence=”10″ Title=”$LocLabels:Sample.contact.CustomTab.CustomGroup.Title” Template=”Mscrm.Templates.3.3″>

<Controls Id=”Sample.Form.contact.CustomTab.CustomGroup.Controls”>

<Button Id=”Sample.Form.contact.CustomTab.CustomGroup.ButtonA”

ToolTipTitle=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonA.LabelText”

ToolTipDescription=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonA.ToolTipDescription”

Command=”Sample.Form.contact.ButtonA” Sequence=”10″

LabelText=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonA.LabelText”

Alt=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonA.LabelText”

Image16by16=”/_imgs/ribbon/runreport16.png” Image32by32=”/_imgs/ribbon/runreport32.png” TemplateAlias=”o1″ />

<Button Id=”Sample.Form.contact.CustomTab.CustomGroup.ButtonB”

ToolTipTitle=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonB.LabelText”

ToolTipDescription=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonB.ToolTipDescription”

Command=”Sample.Form.contact.ButtonB” Sequence=”20″

LabelText=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonB.LabelText”

Alt=”$LocLabels:Sample.contact.CustomTab.CustomGroup.ButtonB.LabelText”

Image16by16=”/_imgs/ribbon/runreport16.png” Image32by32=”/_imgs/ribbon/runreport32.png” TemplateAlias=”o1″ />

</Controls>

</Group>

</Groups>

</Tab>

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

<RibbonTemplates Id=”Mscrm.Templates”></RibbonTemplates>

</Templates>

<CommandDefinitions>

<CommandDefinition Id=”Sample.Form.contact.CustomGroup”>

<EnableRules>

<EnableRule Id=”Mscrm.Enabled” />

</EnableRules>

<DisplayRules />

<Actions />

</CommandDefinition>

<CommandDefinition Id=”Sample.Form.contact.ButtonA”>

<EnableRules>

<EnableRule Id=”Mscrm.Enabled” />

</EnableRules>

<DisplayRules />

<Actions>

<JavaScriptFunction Library=”$webresource:new_contact” FunctionName=”fnA”></JavaScriptFunction>

</Actions>

</CommandDefinition>

<CommandDefinition Id=”Sample.Form.contact.ButtonB”>

<EnableRules>

<EnableRule Id=”Mscrm.Enabled” />

</EnableRules>

<DisplayRules />

<Actions>

<JavaScriptFunction Library=”$webresource:new_contact” FunctionName=”fnB”></JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules>

<TabDisplayRule TabCommand=”Sample.Form.contact.CustomTab”>

<EntityRule EntityName=”contact” Context=”Form” AppliesTo=”PrimaryEntity” />

</TabDisplayRule>

</TabDisplayRules>

<DisplayRules />

<EnableRules>

</EnableRules>

</RuleDefinitions>

<LocLabels>

<LocLabel Id=”Sample.contact.CustomTab.Title”>

<Titles>

<Title languagecode=”1033″ description=”My Tab” />

</Titles>

</LocLabel>

<LocLabel Id=”Sample.contact.CustomTab.Description”>

<Titles>

<Title languagecode=”1033″ description=”My Tab” />

</Titles>

</LocLabel>

<LocLabel Id=”Sample.contact.CustomTab.CustomGroup.Title”>

<Titles>

<Title languagecode=”1033″ description=”My Group” />

</Titles>

</LocLabel>

<LocLabel Id=”Sample.contact.CustomTab.CustomGroup.ButtonA.LabelText”>

<Titles>

<Title languagecode=”1033″ description=”A” />

</Titles>

</LocLabel>

<LocLabel Id=”Sample.contact.CustomTab.CustomGroup.ButtonA.ToolTipDescription”>

<Titles>

<Title languagecode=”1033″ description=”Button A” />

</Titles>

</LocLabel>

<LocLabel Id=”Sample.contact.CustomTab.CustomGroup.ButtonB.LabelText”>

<Titles>

<Title languagecode=”1033″ description=”B” />

</Titles>

</LocLabel>

<LocLabel Id=”Sample.contact.CustomTab.CustomGroup.ButtonB.ToolTipDescription”>

<Titles>

<Title languagecode=”1033″ description=”Button B” />

</Titles>

</LocLabel>

</LocLabels>

</RibbonDiffXml>

You can download the complete solution from this location

Download Solution

Hope it helps 🙂

Updating selected records in the contact Grid – CRM 2011

September 1, 2011 8 comments

Hi,

In CRM 2011, we can update selected records in the Grid using Ribbon customizations (i.e., by using a Custom Ribbon Button).

Ribbon button on Grid

Ribbon button on Grid

Steps:-

  • Create a new Solution called “Ribboncustomer” and add ‘contact’ entity and a newly created web resource called ”ribbon.js” with below function

function processrecords(selectedIds) {

if (selectedIds != null && selectedIds != “”) {

var strIds = selectedIds.toString();

var arrIds = strIds.split(“,”);

for (var indxIds = 0; indxIds < arrIds.length; indxIds++) {

updateRecords(arrIds[indxIds]);

}

}

else {

alert(“No records selected!!!”);

}

}

function updateRecords(contactId) {

//Use OData or Soap call to update the record using passed GUID

}

  • Publish the customizations
  • Export the Solutions and Save
  • Unzip the Solution and Open the “customizations.xml” using VS 2010.
  • search for <RibbonDiffXML> node
  • Replace  with below node

      <RibbonDiffXml>

<CustomActions>

<CustomActionId=Sample.Grid.contact.CustomTab.CustomActionLocation=Mscrm.Tabs._childrenSequence=40>

<CommandUIDefinition>

<TabId=Sample.Grid.contact.CustomTabCommand=Sample.Grid.contact.CustomTab

Title=$LocLabels:Sample.contact.CustomTab.Title

Description=$LocLabels:Sample.contact.CustomTab.DescriptionSequence=500>

<ScalingId=Sample.Grid.contact.CustomTab.Scaling>

<MaxSizeId=Sample.Grid.contact.CustomTab.FirstGroup.MaxSize

GroupId=Sample.Grid.contact.CustomTab.FirstGroup

Sequence=10Size=LargeMedium />

</Scaling>

<GroupsId=Sample.Grid.contact.CustomTab.Groups>

<GroupId=Sample.Grid.contact.CustomTab.FirstGroupCommand=Sample.Grid.contact.FirstGroupSequence=10

Title=$LocLabels:Sample.contact.CustomTab.FirstGroup.TitleTemplate=Mscrm.Templates.3.3>

<ControlsId=Sample.Grid.contact.CustomTab.FirstGroup.Controls>

<ButtonId=Sample.Grid.contact.CustomTab.FirstGroup.FirstButton

ToolTipTitle=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText

ToolTipDescription=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.ToolTipDescription

Command=Sample.Grid.contact.FirstButtonSequence=10  LabelText=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText

Alt=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText

Image16by16=/_imgs/ribbon/AddEmail_16.pngImage32by32=/_imgs/ribbon/Email_32.pngTemplateAlias=o1 />

</Controls>

</Group>

</Groups>

</Tab>

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

<RibbonTemplatesId=Mscrm.Templates></RibbonTemplates>

</Templates>

<CommandDefinitions>

<CommandDefinitionId=Sample.Grid.contact.CustomTab>

<EnableRules>

<EnableRuleId=Mscrm.Enabled />

</EnableRules>

<DisplayRules>

<DisplayRuleId=Mscrm.CanWriteContact />

</DisplayRules>

<Actions/>

</CommandDefinition>

<CommandDefinitionId=Sample.Grid.contact.FirstGroup>

<EnableRules>

<EnableRuleId=Mscrm.Enabled />

</EnableRules>

<DisplayRules>

<DisplayRuleId=Mscrm.CanWriteContact />

</DisplayRules>

<Actions />

</CommandDefinition>

<CommandDefinitionId=Sample.Grid.contact.FirstButton>

<EnableRules/>

<DisplayRules/>

<Actions>

<JavaScriptFunctionLibrary=$webresource:new_ShowMessageFunctionName=processrecords>

                <CrmParameterValue=SelectedControlSelectedItemIds />

              </JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules>

<TabDisplayRuleTabCommand=Sample.Grid.contact.CustomTab>

<EntityRuleEntityName=contactContext=HomePageGrid />

</TabDisplayRule>

</TabDisplayRules>

<DisplayRules />

<EnableRules />

</RuleDefinitions>

<LocLabels>

<LocLabelId=Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText>

<Titles>

<Titlelanguagecode=1033description=Update Records />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.Description>

<Titles>

<Titlelanguagecode=1033description=A custom tab for the Contact entity. />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.FirstGroup.Title>

<Titles>

<Titlelanguagecode=1033description=Get IDs Group />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.FirstGroup.FirstButton.ToolTipDescription>

<Titles>

<Titlelanguagecode=1033description=Get the selected GUID’s of Grid items />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.Title>

<Titles>

<Titlelanguagecode=1033description=Custom Tab />

</Titles>

</LocLabel>

</LocLabels>

</RibbonDiffXml>

 

The key node in the above XML is  <CrmParameterValue=”SelectedControlSelectedItemIds” />

<CommandDefinitionId=Sample.Grid.contact.FirstButton>

<EnableRules/>

<DisplayRules/>

<Actions>

<JavaScriptFunctionLibrary=$webresource:new_ShowMessageFunctionName=processrecords>

<CrmParameterValue=SelectedControlSelectedItemIds />

</JavaScriptFunction>

</Actions>

</CommandDefinition>

We are passing “SelectedControlSelectedItemIds” (i.e.,Selected record Guid’s) to the JScript function. Multiple Id’s seperate by ‘,’.

 

  • We are done with customization part, zip the files and Import the solution & publish all customizations.
  • Clear the cache and refresh the browser and you will get the custom tab with “Update Records” button.

** Below are few more key <CrmParameterValue> that can be passed as parameter **

SelectedEntityTypeCode : A number representing the unique type of entity for a record selected in a grid. The Entity type code will vary
between deployments.
SelectedEntityTypeName : A string representing the unique name of the entity for a record selected in a grid.
FirstSelectedItemId : Provides one GUID identifier as a string for the first item selected in a grid.
SelectedControlSelectedItemCount : The number of selected items in a grid.

SelectedControlSelectedItemIds : A string array of GUID Id values for all selected items in a grid.

SelectedControlAllItemCount : A string array of GUID Id values for all selected items in a grid.
SelectedControlAllItemIds : A string array providing the GUID Id values for all items displayed in a grid.
SelectedControlUnselectedItemCount : The number of unselected items in a grid.
SelectedControlUnselectedItemIds : A string array of GUID Id values for all unselected items in a grid.

Hope it helps 🙂