Friday, 1 January, 2100

Microsoft Dynamics CRM 2011 Notebook


In this post, I am going to note down all the useful add-onsinformation, tips and tools regarding with MS CRM 2011.



Add-ons
Auto Number [jaimieji]
Formula Manager
Fullname Plugin (CodePlex)
Global Quick Search (CodePlex)
Global Search Add-ons
Google Maps Viewer (CodePlex)
Many-to-Many (N:N) Relationship Entity View
Multi File Upload control
Record Recovery by CRM Codex
Universal Search (MSPinPoint)
Update Notifications
Workflow Manipulation Library (CodePlex)
Workflow Utilities by Gonzalo (CodePlex)
Workflow Utilities by Sonoma
XrmSvcToolkit (JavaScript Library for Microsoft Dynamics CRM 2011) (CodePlex)





Information
New Features in Microsoft Dynamics CRM 2011
MSDN Library: What's New for Microsoft Dynamics CRM 2011
Dynamics Exchange: What’s New in CRM 2011 Part 1
Dynamics Exchange: What’s New in CRM 2011 Part 2
Dynamics Exchange: What’s New in CRM 2011 Part 3

Best Practices for Developing with Microsoft Dynamics CRM 2011
JavaScript Development Cheat Sheet
Kerberos in Load Balanced Environments
List of Object Types in Dynamics CRM 2011
Microsoft Dynamics CRM 2011 Administrator's Guide
Microsoft Dynamics CRM 2011 Implementation Guide
Microsoft Dynamics CRM 2011 Licensing
Microsoft Dynamics CRM 2011 Licensing & Pricing Guide
Microsoft Dynamics CRM 2011 User’s Guide
Mobile Express: Features and Limitations
More than 500 videos dedicated to Microsoft Dynamics CRM 2011
Surviving CRM: Dynamics CRM 2011 Walkthrough Part 1: new features in 74 slides
Surviving CRM: Dynamics CRM 2011 Walkthrough Part 2: another 100+ slides of new features
TechNet System Requirements and Required Components for MS CRM 2011
Troubleshooting Kerberos Authentication





Tips
.NET
Accessing and filtering WCF Data Service (oData) from sandboxed Plugin

General
Adding CRM Report on an Entity Form
Adding Images into a knowledge base article
Adding New Report Category
Adding Tabs in Forms as CRM4.0
Asynchronous Ribbon Enable Rules and Executing Workflows from the Ribbon
Building a Web Application That Connects to MS CRM 2011 Using Developer Extensions
Changing default organization for a CRM user
Changing execution time of Recurring System Jobs
Changing Form Header and Footer Colors
Changing Icon for a Custom Entity
Changing maximum no. of controls in Dashboards
Cleaning up CRM Sync Entry tables
Colorize Grid Rows
Communicating Custom ASPX pages with MS-CRM 2011 running IFD
Controlling CRM Popup Windows (Open Popups in a New Tab)
Converting Managed to Unmanaged Solution
Copy a Dynamics CRM 2011 Process
Creating Custom Filtered Lookup to Filter Records Based on Start and End date
Creating Custom Workflow Step by Step (Part 1, Part 2)
Creating Early-Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe)
Creating New Organization
Creating Personal View
Creating & Editing Templates for Marketing Emails
Creating Simple Webpage Leveraging The CRM 2011 IOrganizationService Web Service
Creating Workflow in CRM to Alert a Record’s Owner When an Activity/Note Is Added
CrmSvcUtil (How to use Part 1, Part 2) (Extending Part 1, Part 2)
Deep Queries for Subgrids
Deleting ‘Two Option’ or ‘Bit’ fields which are used in Workflows
Difference between Secure & Unsecure Configuration in Plugin Registration tool
Difference between Custom Entity and Custom Activity
Disable Duplicate Detection Save button on Popup
Enabling Kerberos for Microsoft Dynamics CRM 2011
Export entities from one organization and import to another while changing the ownership of the entity
Fetch-Xml based Reports: Bits & Pieces
Getting Started with CRM Online Fetch XML Reporting
Getting Service URL Alternative to context.getServerUrl()
Hiding Left Navigation Menu Items in an Entity Form using Javascript
Hiding Left Navigation from Form
Hiding Reports from Certain Users
Hiding Toolbar from the SSRS Report while using them in Dashboard
How to add images into a knowledge base article
How to install Microsoft Dynamics CRM 2011 without an Internet Connection
How to open CRM as a different user
How to Set a Read-Only Field and Capture a User’s Response Using a Dialog
How to Set up Remote Debugging for PluginsHow to Setup Visual Studio Remote Debugging
How to use “ClientGlobalContext.js.aspx” in Web Resource HTML
Import of marketing list members using standard import with small extensions
Importing Attachments Programmatically
Importing File Attachments using Import Data wizard
Importing Data using Data Import Wizard
Improving CRM Performance under Windows 2008 using IIS7 Output Caching feature
Increase the records per page to more than 250 rows
Installing 2-server CRM 2011 with Service Accounts and Minimum Permissions
Installing CRM 2011 via Command Line and XML Config File
Installing Rollup Update without updating the database
Javascript Intellisense
Link two subgrids on a form together (parent-child-grids)
Merging Custom Entity Records with Dialog
Microsoft Dynamics CRM 2011 Style Guide
Modifying “Created On” Value (Part 1Part 2)
Modifying Duplicate Detection View
Multi Select OptionSet
N-N Relationship control: Checklistbox style
Outer Joins in Fetch XML Queries
Pass Custom Parameters to an entity form through a URL
Qualifying a Lead using a Dialog Process
Query Expression No Lock Property
Reassigning All of the Records Owned by a User
Recreating Goals with a Dialog
Reference an image in Web Resource from Site Map or Ribbon
Removing Decimals from Chart Labels
Resetting the Dynamics CRM 2011 Ribbon
Resolving Unique Column Names Error with the OrgDbOrgSettings Tool
Restrict/Hide Sitemap SubArea by Security Role
Scheduling Work Hours and Business Closure
Service Contracts & Service Scheduling
Setting a Blank iFrame
Setting Caller (Sender) Field Dynamically
Setting Default View in the Sitemap
Skip Pending E-mail Warning on Login
Sharing Secured Fields
Single Sign-on from a Custom Web Page
Solution package using Visual Studio 2011
Solutions in CRM 2011 – Management and Best Practices (Part 1, Part 2, )
Steps to change Server URL/Machine name after deploying
Timeouts and Limits
Triggering Plug-in From a Ribbon Button
Triggering Save of ASPX pages within iFrame onSave of the form
Turn off 5000 limit on data retrieval via SDK
Understanding Createdon and Overriddencreatedon
Unmasking CRM's PrincipalObjectAccess table
Using Dialogs for Multi-Select OptionSets
Using Dialog to Create Multiple Records
Using PowerShell to Enable SDK Message Throttling
When should I use plug-ins vs. custom workflows?
Workaround for 10,000 Record Limit on Excel Exports
XML Chart Editing

JavaScipt
Accessing the Parent Form from a Child Form
Add notifications to entity form
Adding CRM 2011 Style Buttons
Basic JavaScript Reference
Bulk refresh of user details from AD
Bypassing Prompt and Refresh the Form
Calling External Webservice with Javascript Asynchronously
Canceling the Save Operation
Change the default view of a view selection combo box
Close MS CRM 2011 Form without Prompt
Cross Domain Calls Part 1, Part 2,
Debugging CRM JavaScript code in IE8
Debugging JavaScript
Different Field Widths within same Column
Disable the Sub-Grid
Disabling all Fields on the Form
Display an Entity Form Based on the OptionSet Field
Display Lookup as a Dropdown
Dynamic Cascading Picklists
Dynamically Show Different Form onLoad (Another Post)
Enable Disable Notes Control
Events in onSave method (List of event.Mode)
Excessive Sub-Gridding for more than 4
Extended Handling of Save Events
Filtered Lookup for "Add Existing..." Button of a CRM N:N View
Filtered Lookup view using JavaScript
Get Currency Symbol Based on Currency ID
Get Current User Date and Time Format setting
Get Current User ID and Name
Get Selected Record Guid from a Subgrid
Getting IFrame Window Reference With contentWindow
Hide Form Left Navigation JavaScript
Insert Custom button on CRM Form using Javascript
JavaScript Bookmark Series (Part 1, Part 2, Part 3)
JScript Library of Common Functions by Gareth Tucker
Link two subgrids on a form together (parent-child-grids)
Lookup data from a related entity (Lookup) using JScript and the XrmServiceToolkit
New Xrm.Utility Functions in Update Rollup 8
Parameters from Subgrids
Pass Microsoft Dynamics CRM Data From a Page as a Parameter to Ribbon Actions
Performing Create Update Delete Operations synchronously in CRM 2011 through OData JSON
Populate Lookup Field with String Value (without GUID) using Automatic Resolution
Populate Regarding Attribute in New Email Form
Read Records Synchronously using OData JSON
Reducing Javascript Code Footprint with Microsoft Ajax Minifier tool
Refresh Opening Grid View from a Form
Refresh the Homepage Grid
Retrieve all of the field names in a Tab
Script# (C# to Javascript) Meets Dynamics CRM 2011
Set Field Values Using Parameters Passed to a Form
Setting Default Entity Type and Default View for Regarding/Customer Lookup
Setting focus on a SubGrid (Solution)
Setting Lookup Value
Setting Tooltips for Disabled Ribbon Buttons
Show all Sub-Grids data in entity form (More then 4+ Sub-Grids)
Show Loading message during function execution in CRM Form
Showing Custom Alerts in notifications area
Showing Custom Form Alerts
Submit a Bulk Duplicate Detection Job
Update records of a Sub-Grid using OData JSON JQuery
Using Advanced Find to View Appointments and Recurring Appointments

Plugin
Associate plugin for many to many relationship
CallerOrigin in plugins
Create a Change Log using PreEntityImage and PostEntityImage
Debugging Plug-Ins
Download the Attachment of a Note within a Plugin

Getting state of a record in Plugin and using setStateDynamicEntity

Hiding System/Custom Views
QualifyLead PlugIn
Read Configuration file (Web resource - Data (Xml)) in CRM-Plugin
Restrict Entity Activate, Deactivate Security Privileges
Step by step plugin tutorial using Developer's Toolkit Part 1
Step by step plugin tutorial using Developer's Toolkit Part 2
Step by step plugin tutorial using Developer's Toolkit Part 3
Triggering a plugin on Sharing a Record
Triggering Plugins / Workflows when Associating Entities (N:N)
Update the parent record when children records are created or updated
Update children records when parent record is updated
Using Plug-Ins To Modify Views
Working with Field Level Security from a Plugin

Process
Adding Record to Queue via Workflow
Assign Owner and Route Case to Queue Using Workflow
Create Custom Workflow Activities
Populate Two Options values when creating a record in a dialog
Round Robin Assignment
Send Workflow Email from Executing User
Use a Dialog to Create Multiple Records

Report
Converting a SQL report to FecthXML
Creating custom SSRS report in MSCRM
Creating Reports in Microsoft Dynamics CRM 2011
Custom Report in MSCRM using Stored Proc
CRM Reporting Tips And Hints – II. CRMAF binding not working
Excel Export Formatting
Hierarchical report in SSRS to show users and their managers (CRM)
Pre-Filtering for CRM Reporting
Tips for better performing Microsoft Dynamics CRM SQL reports in SSRS

Ribbon
Adding Attach File button on Custom Activity Type Entity
Adding CustomRule to Out of Box Ribbon Button
Adding Reply Button onto Custom Activity
Enable/Disable Out of Box buttons (Sub-Grid) based on a custom rule
Enable/Disable Ribbon button dynamically based on a form value
Hiding “Add Existing” button
Launch a Dialog on click of custom ribbon button
Managing Access to Activate/Deactivate Ribbon Buttons
Referencing Multiple Javascript Libraries in Homepage Ribbon Buttons
Ribbon Customisation Display Rules
Understanding CRM Ribbon XML - Part 1: ribbon content and structure
Understanding CRM Ribbon XML - Part 2: updating the ribbon
Understanding CRM Ribbon XML - Part 3: Group Templates


Sample Codes
.NET Sample Codes
Adding a Custom Attribute to an Entity
Adding Record to Queue via C# Code
Associate Two Entity Instances
Assign a Record to a Team or User
Assigning a Security Role to Team
Assigning an Entity to a User
Book an Appointment Using C#
Booking an Appointment 
Check if an Entity can be the Primary Entity in a One-To-Many Relationship
Check if an Entity can be the Referencing (Many) Entity in a One-To-Many Relationship
Check if an Entity can Participate in Many-To-Many Relationships
Checking  if the date is a business day
Close an Opportunity Record as Won
Code to Create, Retrieve, Deactivate, Renew an Invoiced Contract and Contract Template
Code to Create Update , Retrieve and Delete Email Attachment
Code to Create, Validate and Close Incident and Appointment
Create a New Entity
Create a One-To Many Relationship Between Two Entities
Create an OptionSet
Creating and Attaching Attachment to Email Template
Creating and Distributing Campaign with Dynamic and Static List
Creating and Distributing Quick Campaign
Creating Custom Activity and Attributes
Creating Custom Entity and Attribute using C#
Creating Letter Entity record
Creating, Updating, Retrieving and Associating Connection Role and Connections
Creating WorkFlow Activity and the use of Output parameters
Create, Assign and Retrieving Field Permission in C#
Determining if an Entity is Eligible to Participate in a Relationship Type Using VB.NET
Disassociate Two Entity Instances
Delete Custom Attribute From an Entity
Delete E-mail Attachments
Delete OptionSet
Delete Relationship Between Entity Types
Export a Saved Import Map using C#
Fetching team members for selected Team
Getting OptionSetValue Label Text
Getting Total Record Count
Getting Total Members count of a Dynamic Marketing List
Merge and Update Merged Entity Record Content
Microsoft Dynamics CRM SOAP Logger
Programmatically change the customization for a system/custom entity
PublishXmlRequest SDK message to publish an Entity or a Web Resource
Querying Audit Data to Determine When A User Last Logged In
Retrieve Optionset Labels and Values
Qualifing a Lead
Querying Data with QueryByAttribute
Querying Data with QueryExpression
Querying User's Schedule for Open Time Slots Using VB.NET
Querying User's Schedule for Open Time Blocks Using C#
Reassigning and Publishing Workflow
Retrieve an Entity Instance
Retrieve Metadata for an Entity in C#
Retrieve Metadata for an Entity in VB.NET
Retrieve Metadata For All Entities
Retrieve OptionSet Text using C#
Retrieving Schedule of Multiple users
Retrieving Schedule of System user
Retrieve Used Resources for an Organization and Storage Quota Info
Retrieving all the members of a Static Marketing List
Run ondemand workflow from C# code
Sending Email to Unresolved Recipients
Setting Values Programmatically via the CRM 2011 SDK
Share/Unshare a Record with a Team
Sharing a Record
Submit a Bulk Duplicate Detection Job Using C#
Update an Entity Instance
Update the Last Form Viewed in UserEntityUISettings Entity
Use DeleteRequest to Delete an Entity
Using the Early Bound Entity Classes for Create, Update, and Delete
Using wsdlbasedproxies with Claims authentication
Validating and Setting State of Entity Record
Validating the Constraints of an Appointment are Met Using C#

JavaScript Sample Codes
Adding Record to Queue via JScript Code
Book an Appointment Using JScript
Checking user rights on client side
Create, Update , Delete Record using Javascript
Export a Saved Import Map using JScript
InstantiateTemplateRequest using Javascript
Querying Audit Data to Determine When A User Last Logged In
Querying User's Schedule for Open Time Blocks
Retrieving all the members of a Static Marketing List
Retrieving Metadata for an Entity in JScript
Soap XML Retrieve using javascript
Soap XML RetrieveMultiple using javascript
Submit a Bulk Duplicate Detection Job using JScript
Validate the Constraints of an Appointment are Met using JScript

REST Endpoint / Silverlight
Applying Dynamics CRM 2011 styles to a Silverlight application
Associate an Entity Record with Another
Consuming custom WCF Data Services (oData) Endpoint (Javascript/jQuery and c#) (Part 1, Part 2)
Create Entity in Microsoft Dynamics CRM 2011 from Silverlight
Create, Update, Delete , Retrieve, MultipleRetrieve using Organization OData Service
Delete an Entity Record
Disassociate an Entity Record From Another Entity Record
Debugging Silverlight Web Resources without deploying
Early bound Entity Types in Silverlight
Getting Current User ID and Organization ID in SIlverlight Using WhoAmIRequest
Getting Text Value of an OptionSetValue Using LINQ
Interact with CRM form objects from Silverlight through the HTML Bridge
Scaling Silverlight Web Resources
Using the SOAP Endpoint for Web Resources with Silverlight
Using the Dynamic Type in Silverlight to Easily Access The Client-Side API

SQL



Others
Convert VDI to VMDK – VirtualBox to VMware
Duplicate a Virtual Box Image
Edit the password policy on Windows Server 2008 R2 with Active Directory
Encrypt web.config files
How to Resize a Microsoft Virtual Hard Drive (VHD) File
How to Resize an Oracle VM VirtualBox 4 .vdi file
Manual mounting shared folder in Oracle VM VirtualBox
Shrinking VirtualBox VDI Files




Tools
Bulk Export Solution (CodePlex)
CrmDiagTool (CodePlex)
Connection Control Assembly for Custom Tools (CodePlex)
Count CRM Users
CRM 2011 Visual Studio Tools
CRM Trace Log Viewer
Custom Code Validation Tool (Download)
Diagnostic Tool to check On Premises CRM 2011 Server Performace
Dynamics XRM Tools (CodePlex)
Dynamics CRM 2011 T4 Code Generator (CodePlex)
Excel Data Model Addin (CodePlex)
Excel Export Record Limit Increment Tool
Export Web Resources
Find Privilege Utility
Iconator (CodePlex)
Import/Export N to N Relationships Tool (CodePlex)
JavaScript SOAP Request Formatter (CodePlex)
JavaScript Model Generator (CodePlex)
JavaScript Web Resource Manager (CodePlex)
Maintenance Job Editor (CodePlex)
Metablast Schema Documentation
Metadata Browser [SDK]
Metadata Browser [3rd party]  (CodePlex)
Metadata Document Generator (CodePlex)
MSCRM 2011 ToolKit (CodePlex) (Reference Data Transporter, Data Export Manager, Export Entities Structure, Deployment Properties, Solutions Export Manager, Workflow Execution Manager, Records Counter)
OData Query Designer (CodePlex)
OptionSet Helper from CRM SDK
OptionSet Manager by CrmXpress (CodePlex)
OptionSet Utility & Community Library
OrgDBOrgSettings Tool
Plugin Configuration
Plugin Testing Tool (CodePlex)
Pragma Toolkit: Ribbon, SiteMap Editor (CodePlex)
Ribbon Editor (CodePlex)
Ribbon Workbench
Role Updater (CodePlex)
RunAs GUI tool
Searchable Property Updater (CodePlex)
Sharing Summary (CodePlex)
SiteMap Editor (CodePlex)
SiteMap Editor by Microsoft Dynamics Labs
Smart Soap Logger
Solution Import Tool (CodePlex)
Solution Extender (CodePlex)
Sonoma Partners Universal Settings Utility
Stunnware Tools (FetchXML, QueryExpression Builder)
Tool that increases limit of record during export to Excel
Trace Helper
User Settings Utility (CodePlex)
User Settings Console (CodePlex)
VB.Net SoapLogger (CodePlex)
View Layout Replicator (CodePlex)
Visual Ribbon Editor Tool (CodePlex)
Web Resource Manager (CodePlex)





Solution Samples
Building an HTML/JScript Configuration Web Resource (Download Sample)
Call Centre Optimised CRM–An Example Solution
Creating Automatic Follow-up Activities
Microsoft Dynamics CRM in the Call Center (Keeping Multiple Source System Data in Sync, Maintaining Data Quality, How to leverage Multiple Source Systems through CRM)
Track Last Contacted Date for Customers




Others
Resources
Common CRM interview questions
MS CRM 2011 Technical Interview Question Part -1
MS CRM 2011 Technical Interview Question Part -2

Developer Training Videos
Excellent video resources CRM 2011
100+ videos dedicated to Microsoft Dynamics CRM 2011

CRM 2011 Build and version numbers
Microsoft Dynamics CRM Server 2011
Microsoft Dynamics CRM 2011 Development Resources
Microsoft Dynamics CRM 2011 for Microsoft Office Outlook
Microsoft Dynamics CRM 2011 List Component for Microsoft SharePoint Server 2010
Microsoft Dynamics CRM 2011 E-mail Router
Microsoft Dynamics CRM 2011 Report Authoring Extension
Microsoft Dynamics CRM 2011 Implementation Guide
Microsoft Dynamics CRM 2011 Software Development Kit (SDK)
Microsoft Dynamics CRM 2011 Developer Training Kit
Microsoft Dynamics CRM 2011 Performance Counters
Microsoft Dynamics CRM 2011 Optimization guide
Optimizing and Maintaining the Performance of a Microsoft Dynamics CRM 2011 Server Infrastructure
Performance Toolkit for Microsoft Dynamics CRM 2011
Update Rollup 1 (Build Number 5.0.9688.1045)
Update Rollup 2 (Build Number 5.0.9688.1155)
Update Rollup 3 (Build Number 5.0.9688.1244)
Update Rollup 4 (Build Number 5.0.9688.1450)
Update Rollup 5 (Build Number 5.0.9688.1533)
Update Rollup 6 (Build Number 5.0.9688.1992)
Update Rollup 7 (Build Number 5.0.9690.2165)
Update Rollup 8 (Build Number 5.0.9690.2243)
Update Rollup 10 (Build Number 5.0.9690.2730)
Update Rollup 11 (Build Number 5.0.9690.2835)
Update Rollup 12 (Build Number 5.0.9690.3218)

Installation and Configuration
Connector for Microsoft Dynamics installation guides
Installing Active Directory On Windows Server 2008
Installation of Microsoft Dynamics CRM 2011 Standalone Sandbox Using VirtualBox Part 1
Installation of Microsoft Dynamics CRM 2011 Standalone Sandbox Using VirtualBox Part 2

Optimizing and Maintaining Client Performance for Microsoft Dynamics CRM 2011 and CRM Online
Optimizing and Maintaining the Performance of a Microsoft Dynamics CRM 2011 Server Infrastructure

Integration with SharePoint 2010
Integration with SharePoint: Custom Document Management

Rename a Windows Server 2008 domain
Using Windows Server 2008 as a Workstation

Articles
Getting started with customer service processes


Others
Retrieving Multiple Related Entities Asynchronously
Key


90 Day Microsoft Dynamics CRM Server 2011 (no CAL limit):
MQM2H-JYYRB-RRD6J-8WBBC-CVBD3

90 Day Microsoft Dynamics CRM Workgroup Server 2011 (5 CAL limit):
H84KC-JH8DF-7PDYK-TXBXR-2RMMT

Wednesday, 8 May, 2013

Creating Forward Email through SDK

Here's the sample code to create Forward Email through SDK
 private static Guid CreateForwardEmail(Guid existingEmailID)  
 {  
   Entity existingEmail = _service.Retrieve("email", existingEmailID, new ColumnSet("from", "createdon", "to", "cc", "subject", "description", "regardingobjectid"));  
   Entity oEmail = new Entity("email");  
   oEmail["regardingobjectid"] = existingEmail["regardingobjectid"];  
   oEmail["subject"] = "FW: " + existingEmail["subject"];  
   oEmail["description"] = "<FONT size=2 face='Tahoma, Verdana, Arial'><BR>------------------- Original Message -------------------<BR>";  
   oEmail["description"] += "<B>From:</B> " + ((EntityReference)((Microsoft.Xrm.Sdk.EntityCollection)existingEmail["from"]).Entities[0]["partyid"]).Name + "<BR>";  
   oEmail["description"] += "<B>Received:</B> " + ((DateTime)existingEmail["createdon"]).ToString("d/M/yyyy h:m tt") + "<BR>";  
   oEmail["description"] += "<B>To:</B> ";  
   EntityCollection toParties = (Microsoft.Xrm.Sdk.EntityCollection)existingEmail["to"];  
   bool firstRecord = true;  
   foreach (Entity to in toParties.Entities)  
   {  
     if (firstRecord)  
       firstRecord = false;  
     else  
       oEmail["description"] += "; ";  
     oEmail["description"] += ((EntityReference)to["partyid"]).Name;  
   }  
   oEmail["description"] += "<BR>";  
   oEmail["description"] += "<B>Cc:</B> ";  
   EntityCollection ccParties = (Microsoft.Xrm.Sdk.EntityCollection)existingEmail["cc"];  
   firstRecord = true;  
   foreach (Entity cc in ccParties.Entities)  
   {  
     if (firstRecord)  
       firstRecord = false;  
     else  
       oEmail["description"] += "; ";  
     oEmail["description"] += ((EntityReference)cc["partyid"]).Name;  
   }  
   oEmail["description"] += "<BR>";  
   oEmail["description"] += "<B>Subject:</B> " + existingEmail["subject"].ToString() + "</FONT><BR><BR>";  
   oEmail["description"] += "<FONT size=2 face='Tahoma, Verdana, Arial'>" + existingEmail["description"].ToString() + "</FONT>";  
   Guid newEmailID = _service.Create(oEmail);  
   QueryByAttribute attachmentQuery = new QueryByAttribute("activitymimeattachment");  
   attachmentQuery.ColumnSet = new ColumnSet("objecttypecode", "mimetype", "filename", "body");  
   attachmentQuery.AddAttributeValue("objectid", existingEmail.Id);  
   attachmentQuery.AddAttributeValue("objecttypecode", "email");  
   EntityCollection ecAttachments = _service.RetrieveMultiple(attachmentQuery);  
   foreach (Entity attachment in ecAttachments.Entities)  
   {  
     attachment.Id = Guid.Empty;  
     attachment.Attributes.Remove("activitymimeattachmentid");  
     attachment["objectid"] = new EntityReference("email", newEmailID);  
     _service.Create(attachment);  
   }  
   return newEmailID;  
 }  

Friday, 8 June, 2012

Hiding Left Navigation Menu Items in an Entity Form using Javascript in MS CRM 2011


In the form designer, you can remove the items from the left navigation. If you remove all the items in the navigation area, the group header will be hidden as well except for some navigation areas like Common, Marketing and Processes.

But if you're looking for a solution to hide the navigation items based on the condition, values, etc. you can use the following JavaScript to hide them.

 var navitem = Xrm.Page.ui.navigation.items.get("nav_new_test_new_testchild") // for e.g "navContacts";    
 if (navitem != null)  
 {  
   navitem.setVisible(false);  
 }  

Normally, the name of the navigation is

  • "nav" + Entityname in plural for the system entities or
  • "nav_" + relationship name between these 2 entities

but there are some exception cases for the system entities like "navOpps" so that if it's not working just by guessing, you can use IE Developer Toolbar to find the name of the navigation item.

Hiding the navigation items with Java Script will still leave the header of the navigation area though.

Thursday, 7 June, 2012

Referencing Multiple Javascript Libraries in Homepage Ribbon Buttons

When we develop JavaScript functions for the Actions and CustomRules of the Ribbon buttons in CRM 2011, we may need to reference the common JavaScript library or other javascript libraries. For the ribbon buttons on the form, we can simply add those additional libraries in the Form Libraries and call the functions in those libraries but for Homepage ribbon buttons, we need to try a different approach to achieve it.

 <Actions>   
 <JavaScriptFunction Library="$webresource:new_MainEntityLibrary" FunctionName="Test" />   
 <JavaScriptFunction Library="$webresource:new_CommonLibrary" FunctionName="isNaN" /> //This is the additional library  
 </Actions>  

The FunctionName of the JavaScriptFunction action tag is required so that putting isNaN as a value will do the trick instead of calling the dummy function with no action.
This method can also be used for Sub-grid ribbon buttons if the sub-grid is displayed is multiple forms and adding those common libraries in all those forms is a tedious job.


Another way of doing this is to load another JavaScript webresource by calling the following JavaScript function and passing the name of the web resource.
e.g.
LoadWebResource("new_commonlibrary.js");

 LoadWebResource = function(resourceName)  
 {  
      var httpRequest = new ActiveXObject("Msxml2.XMLHTTP");  
      httpRequest.open("GET", "/" + ORG_UNIQUE_NAME + "/webresources/" + resourceName, false);  
      httpRequest.send(null);  
      try  
      {  
           eval(httpRequest.responseText);  
      }  
      catch (e)  
      {  
           alert("Error loading " + resource + ":\n" + e.description);  
      }  
 }  

Tuesday, 27 March, 2012

Retrieve Label/Values of Option Set/Two Options Attributes using SQL Script

When you want to retrieve the list of  Label and Values of Option Set and Two Options attributes for documentation, development or whatever purpose, you can query by using the following SQL Script.
You will have to remove/modify the two lines of conditions ("new_testentity" and "new_testoptionsetattribute") accordingly to your requirement.

 SELECT DISTINCT  
         Entity.LogicalName AS EntitySchemaName  
 ,        Attribute.LogicalName AS AttributeSchemaName  
 ,        OptionSet.Name AS OptionSetName  
 ,        AttributePicklistValue.Value AS OptionValue  
 ,        LocalizedLabel.Label AS OptionText  
 FROM    MetadataSchema.LocalizedLabel  
     INNER JOIN MetadataSchema.AttributePicklistValue ON LocalizedLabel.ObjectId = AttributePicklistValue.AttributePicklistValueId  
     INNER JOIN MetadataSchema.OptionSet ON AttributePicklistValue.OptionSetId = OptionSet.OptionSetId  
     INNER JOIN MetadataSchema.Attribute ON OptionSet.OptionSetId = Attribute.OptionSetId  
     INNER JOIN MetadataSchema.Entity ON Attribute.EntityId = Entity.EntityId  
 WHERE LocalizedLabel.Label <> ''  
 AND Entity.LogicalName = 'new_testentity'  
 AND Attribute.LogicalName = 'new_testoptionsetattribute'  
 ORDER BY Entity.LogicalName, Attribute.LogicalName, AttributePicklistValue.Value  

This is the alternative query over StringMap table.

 SELECT * FROM StringMap SM  
 INNER JOIN Entity E ON E.ObjectTypeCode = SM.ObjectTypeCode  
 WHERE E.Name = 'new_testentity'  
 AND SM.AttributeName = 'new_testoptionsetattribute'  

Populate Regarding Attribute in New Email Form


When we created a new email for a record by Clicking “New Activity” button in the “Activities” associated view, it will prompt us to select the activity type.

And when the user select E-mail and click OK, the new email form will is shown with the “From” attribute populated with the current user and the “Regarding” attribute populated with the record from which we clicked “New Activity” and everything is fine.


According to the users’ requirement, there’s a case that we have to show the Subgrid of email related to the record on the form. And that’s where the problem started. When the user click “Add New E-mail” button from the Subgrid and the new Email form is loaded, the record is not populated in the regarding attribute. So, the user demands for the same functionality as the new Activity since it would be a hassle to select the Regarding attribute manually.


So, my solution was writing a JavaScript code at the onLoad of the Email form which will auto populate the “Regarding” attribute if email form is loaded from a record. In order to fill up the Regarding lookup value, we’ll need the RecordId, LogicalName of the Entity and PrimaryName (for display). The logic of the code is to check the _CreateFromId and _CreateFromType from the QueryStringParameters and fetch the required parameters using RetrieveAllEntitiesAsync from "SDK.MetaData.js" of Microsoft. First, you need to create a new JavaScript webresource, copy the code of "SDK.MetaData.js" and add it into the Form Libraries of the Email form. Then, add the following codes in the JavaScript Library of Email form and call the OnLoad function.

 function OnLoad()  
 {  
     var FORM_TYPE_CREATE = 1;  
       
       
     if (Xrm.Page.ui.getFormType() == FORM_TYPE_CREATE && Xrm.Page.context.getQueryStringParameters()["_CreateFromId"] != null && Xrm.Page.context.getQueryStringParameters()["_CreateFromType"] != null)  
     {  
         SDK.MetaData.RetrieveAllEntitiesAsync(SDK.MetaData.EntityFilters.Entity, false, successRetrieveAllEntities, errorRetrieveAllEntities);  
     }  
 }  
   
 function successRetrieveAllEntities(entityMetadataCollection)  
 {  
     var entityName = "";  
     var PrimaryNameAttribute = "";  
     for (var i = 0; i < entityMetadataCollection.length; i++)  
     {  
         if (entityMetadataCollection[i].ObjectTypeCode == Xrm.Page.context.getQueryStringParameters()["_CreateFromType"])  
         {  
             entityName = entityMetadataCollection[i].LogicalName;  
             PrimaryNameAttribute = entityMetadataCollection[i].PrimaryNameAttribute;  
             break;  
         }  
     }  
       
     if (entityName != "" && PrimaryNameAttribute != "")  
     {  
         var displayValue = RetrieveMultiple(entityName, PrimaryNameAttribute, entityName + "id|Equal|" + Xrm.Page.context.getQueryStringParameters()["_CreateFromId"]);  
         Xrm.Page.getAttribute("regardingobjectid").setValue( [{id: Xrm.Page.context.getQueryStringParameters()["_CreateFromId"], name: displayValue, entityType: entityName}]);  
     }  
 }  
   
 function errorRetrieveAllEntities(error)  
 {  
     alert(error.message);  
 }  
   
 function RetrieveMultiple(entity, attribute, condition)  
 {  
     // Usage => RetrieveMultiple("new_entityname", "new_attribute1|new_attribute2|new_attribute3", "new_attribute1|Equal|value1||new_attribute2|Like|value2||new_attribute3|NotNull";  
     // Refer to the following link for more operators >> http://msdn.microsoft.com/en-us/library/bb959309.aspx  
       
     // Prepare variables to retrieve the records.  
     var attributes = attribute.split('|');  
     var authenticationHeader = GenerateAuthenticationHeader();  
       
     // Prepare the SOAP message.  
     var xml = "<?xml version='1.0' encoding='utf-8'?>"+   
     "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+  
     " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+  
     " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+   
     authenticationHeader+   
     "<soap:Body>"+   
     "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+   
     "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+  
     " xsi:type='q1:QueryExpression'>"+   
     "<q1:EntityName>" + entity + "</q1:EntityName>"+   
     "<q1:ColumnSet xsi:type='q1:ColumnSet'>"+   
     "<q1:Attributes>";  
       
     for (i = 0; i < attributes.length; i++)  
         xml += "<q1:Attribute>" + attributes[i] + "</q1:Attribute>"  
       
     xml +=  
     "</q1:Attributes>"+   
     "</q1:ColumnSet>"+   
     "<q1:Distinct>false</q1:Distinct>"+   
     "<q1:Criteria>"+   
     "<q1:FilterOperator>And</q1:FilterOperator>"+   
     "<q1:Conditions>";  
       
       
     var conditionDetails;  
     var conditions = condition.split('||');  
     for (i = 0; i < conditions.length; i++)  
     {  
         conditionDetails = conditions[i].split('|');  
         xml +=   
         "<q1:Condition>"+  
         "<q1:AttributeName>" + conditionDetails[0] + "</q1:AttributeName>"+   
         "<q1:Operator>" + conditionDetails[1] + "</q1:Operator>";  
           
         if (conditionDetails.length > 2)  
         {  
             xml +=   
             "<q1:Values>"+   
             "<q1:Value xsi:type='xsd:string'>" + conditionDetails[2] + "</q1:Value>"+   
             "</q1:Values>";  
         }  
           
         xml +=   
         "</q1:Condition>";  
     }  
       
     xml +=   
     "</q1:Conditions>"+   
     "</q1:Criteria>"+   
     "</query>"+   
     "</RetrieveMultiple>"+   
     "</soap:Body>"+   
     "</soap:Envelope>";  
     // Prepare the xmlHttpObject and send the request.  
     var xHReq = new ActiveXObject("Msxml2.XMLHTTP");  
     xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);  
     xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");  
     xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");  
     xHReq.setRequestHeader("Content-Length", xml.length);  
     xHReq.send(xml);  
     // Capture the result.  
     var resultXml = xHReq.responseXML;  
   
     // Check for errors.  
     var errorCount = resultXml.selectNodes('//error').length;  
     if (errorCount != 0)  
     {  
         var msg = resultXml.selectSingleNode('//description').nodeTypedValue;  
         //alert(msg);  
         return msg;  
     }  
     // Parse and display the results.  
     else  
     {  
         var results = resultXml.getElementsByTagName('BusinessEntity');  
         var msg = "";  
         if (results.length == 0)  
         {  
             //msg = "No record found with the given criteria.";  
             //alert(msg);  
             //return;  
             return null;  
         }  
         else  
         {  
             var result = "";  
             for (i = 0;i < results.length;i++)  
             {  
                 if (i != 0)  
                     result += '|';  
                 for (j = 0; j < attributes.length; j++)  
                 {  
                     if (i != 0 || j != 0)  
                         result += '|';  
                     if (results[i].selectSingleNode('./q1:'+ attributes[j]) != null)  
                         result += results[i].selectSingleNode('./q1:'+ attributes[j]).nodeTypedValue;  
                 }  
                   
             }  
             return result;  
         }  
     }  
 }  

Leave me a comment if you have any problem with the above code.