Archive
Dynamics CE – Issue while updating ‘Annotation’ record using SDK
Other day, we encountered following error in our plug-in, which has the logic to retrieve and update the ‘objectid’ field (i.e., Associated record) of Annotation record.
‘new_myentity’ with ID XXX-XXXX-XXXX-XXX does not exists
Below is the plug-in code:
var entAnnotation=new Entity(“annotation”);
entAnnotation.Attributes[“objectid”] = new EntityReference(“new_myentity”,”{GUID}”);
crmService.Update(entAnnotation);
We are trying to update ‘objectid’ and from the error, its clear that Object ID (i.e.,GUID) of the ‘new_myentity’ entity does not exists in the application.
But we know that the GUID is of a valid ‘new_myentity’ entity, as that was retrieved using ‘Query Expression’ in previous plug-in statement.
Reason and Fix:
- We must also set ‘objecttypecode’ field as the schema name of the ‘objectid’ of the Annotation record.
- In our case, its ‘new_myentity’.
- Below is the code of Annotation update setting ‘objecttypecode’ field.
var entAnnotation=new Entity(“annotation”);
entAnnotation.Attributes[“objectid”] = new EntityReference(“new_myentity“,”{GUID}”);
entAnnotation.Attributes[“objecttypecode”] = “new_myentity“;
crmService.Update(entAnnotation);
Issue was annoying and took sometime to troubleshoot and find the actual reason.
š
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).
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.CustomAction“Location=“Mscrm.Tabs._children“Sequence=“40“>
<CommandUIDefinition>
<TabId=“Sample.Grid.contact.CustomTab“Command=“Sample.Grid.contact.CustomTab“
Title=“$LocLabels:Sample.contact.CustomTab.Title“
Description=“$LocLabels:Sample.contact.CustomTab.Description“Sequence=“500“>
<ScalingId=“Sample.Grid.contact.CustomTab.Scaling“>
<MaxSizeId=“Sample.Grid.contact.CustomTab.FirstGroup.MaxSize“
GroupId=“Sample.Grid.contact.CustomTab.FirstGroup“
Sequence=“10“Size=“LargeMedium“ />
</Scaling>
<GroupsId=“Sample.Grid.contact.CustomTab.Groups“>
<GroupId=“Sample.Grid.contact.CustomTab.FirstGroup“Command=“Sample.Grid.contact.FirstGroup“Sequence=“10“
Title=“$LocLabels:Sample.contact.CustomTab.FirstGroup.Title“Template=“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.FirstButton“Sequence=“10“Ā LabelText=“$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText
“Alt=“$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText“
Image16by16=“/_imgs/ribbon/AddEmail_16.png“Image32by32=“/_imgs/ribbon/Email_32.png“TemplateAlias=“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_ShowMessage“FunctionName=“processrecords“>
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā <CrmParameterValue=“SelectedControlSelectedItemIds“ />
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā </JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules>
<TabDisplayRuleTabCommand=“Sample.Grid.contact.CustomTab“>
<EntityRuleEntityName=“contact“Context=“HomePageGrid“ />
</TabDisplayRule>
</TabDisplayRules>
<DisplayRules />
<EnableRules />
</RuleDefinitions>
<LocLabels>
<LocLabelId=“Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText“>
<Titles>
<Titlelanguagecode=“1033“description=“Update Records“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.Description“>
<Titles>
<Titlelanguagecode=“1033“description=“A custom tab for the Contact entity.“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.FirstGroup.Title“>
<Titles>
<Titlelanguagecode=“1033“description=“Get IDs Group“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.FirstGroup.FirstButton.ToolTipDescription“>
<Titles>
<Titlelanguagecode=“1033“description=“Get the selected GUID’s of Grid items“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.Title“>
<Titles>
<Titlelanguagecode=“1033“description=“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_ShowMessage“FunctionName=“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 š