Home > CRM 2011, JScript, Ribbon > Updating selected records in the contact Grid – CRM 2011

Updating selected records in the contact Grid – CRM 2011

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 🙂

Advertisement
  1. _Flin_
    November 23, 2011 at 2:58 PM

    Thank you, a great help!

  2. March 7, 2012 at 5:52 PM

    Hello Rajeev,

    Thanks for this post, it is very useful. But I am having an issue regarding an example similar to your post. I hope you can help me with that.

    To update selected records I am using OData and JQuery and to give reference for Json2.js” & “jquery1.4.1.min.js” helper script files I tried following in customizations.xml

    When I use above code I get this error:
    “Error initializing component with element id=’lookupFilterPopupcrmGridrn_myentitycreatedby’ and with type=’Mscrm.LookupFilterPopup’: Unable to set value of the property ‘lookupstyle’: object is null or undefined.”

    And when I use,

    I get ‘$’ is undefined error.

    Please guide me, I really need help.

    Thanks in advance.

    • March 8, 2012 at 9:44 AM

      Hi Mathur,
      When you update the record from ribbon button placed on entity grid, the helper script files wont get loaded by default.
      Thats the reason you get $ undefined error.
      To fix this, you have to load the script files dynamically. This post would help you.

      Thanks,
      Rajeev

      • March 10, 2012 at 12:14 PM

        Hello Rajeev,

        I tried what you said and I am still getting error that –

        Error initializing component with element id=’lookupFilterPopupcrmGridnew_myentitycreatedby’ and with type=’Mscrm.LookupFilterPopup’: Unable to set value of the property ‘lookupstyle’: object is null or undefined

        I am sharing full error log with you,

        Microsoft Dynamics CRM Error Report Contents

        1.0

        Error initializing component with element id=’lookupFilterPopupcrmGridnew_myentitycreatedby’ and with type=’Mscrm.LookupFilterPopup’: Unable to set value of the property ‘lookupstyle’: object is null or undefined

        I need your guidance.

      • March 10, 2012 at 2:46 PM

        Hey Rajeev, thank you so much …. it was my mistake. I was missing jquery1.4.1.js. By code is working after trying this:

        var JScriptminWebResourceUrl = “http://crm2011:5555/dynamics/WebResources/rn_jquery1.4.1.min.js”;
        var xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
        xmlHttp.open(“GET”, JScriptminWebResourceUrl, false);
        xmlHttp.send();
        eval(xmlHttp.responseText);

        var JScriptWebResourceUrl = “http://crm2011:5555/dynamics/WebResources/rn_jquery1.4.1.js”;
        var xmlHttp1 = new ActiveXObject(“Microsoft.XMLHTTP”);
        xmlHttp1.open(“GET”, JScriptWebResourceUrl, false);
        xmlHttp1.send();
        eval(xmlHttp1.responseText);

        var JSONWebResourceUrl = “http://crm2011:5555/dynamics/WebResources/rn_json2.js”;
        var xmlHttp2 = new ActiveXObject(“Microsoft.XMLHTTP”);
        xmlHttp2.open(“GET”, JSONWebResourceUrl, false);
        xmlHttp2.send();
        eval(xmlHttp2.responseText);
        and then update ………………….

        Thanks you soooooooooo much .. you made my day 🙂

  3. Jerry J
    October 8, 2012 at 10:16 PM

    After updating the selected Contact records I need to either refresh the grid or unselect the selected records. What is the best method for doing that? I can reload the form but it goes back to the default view.

  4. sarah
    November 7, 2013 at 8:36 PM

    When I try to import this i get the error below any thoughts
    The ribbon item ‘Sample.Grid.new_wastetrackingform.CustomTab’ is dependent on .

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: