Advertisements

Archive

Posts Tagged ‘ribbon button’

Loading dependent jscript libraries in ribbon button’s execution CRM 2011

Hi,

I have a ribbon button on my “Account” main grid .

I am calling function “sayHello” which is in my web resource “account_ribbon” by defining custom action like below.

<Actions>

<JavaScriptFunction Library=”$webresource:account_ribbon” FunctionName=”sayHello”>

</JavaScriptFunction>

</Actions>

Now the problem is, I need to call another method from my “sayHello” function, which is in other web resource “common”.

Solution :-

The solution is simple. We can add all the required libraries to <Actions> node like below

 <JavaScriptFunction Library=”$webresource:common” FunctionName=”isNaN” />

Note – Since <JavaScriptFunction> requires a function name, pass “isNaN”.

Now my <Actions> node look like below

<Actions>

<JavaScriptFunction Library=”$webresource:account_ribbon” FunctionName=”sayHello”>

</JavaScriptFunction>

<JavaScriptFunction Library=”$webresource:common” FunctionName=”isNaN”>

</JavaScriptFunction>

</Actions>

🙂

Advertisements

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 🙂

New window is opening up on button click in modal dialog

February 1, 2012 1 comment

Hi,

In one of my requirement, I am opening an “.aspx” page in modal dialog on CRM ribbon button click.

My .aspx page has a button and when I click on the button , The same page is opening up in another window

Fix :-

  • Add “base target=”_self” tag to the .Aspx page’s “head” (Refer below)

<head>

<base target=”_self” />

</head>

 

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 🙂