Monday, October 31, 2011

How to copy Microsoft CRM 2011 organization on the same server.

There are many reasons to copy organizations, one of the most common - for testing purpose.
You can do as following:
1. Select a database in SQL Server Management Studio which will be copied (TEST_MSCRM). Right click on the target database -> Tasks -> Backup.


Useful JavaScript commands for Microsoft CRM 2011 - Part 2: Xrm.Page.data.entity.attributes

Useful JavaScript commands for Microsoft CRM 2011 - Part 2: Xrm.Page.data.entity.attributes
Xrm.Page.data.entity.attributes – provides methods to retrieve information and perform actions on attributes.
Command
Description
.addOnChange()
Sets a function to be called when the attribute value is changed.
.fireOnChange()
Causes the OnChange event to occur on the attribute so that any script associated to that event can execute.

Example:
Xrm.Page.getAttribute("CRMFieldSchemaName").fireOnChange();
.getAttributeType()
Returns a string value that represents the type of attribute.
.getFormat()
Returns a string value that represents formatting options for the attribute.
.getInitialValue()
Returns the initial value for Boolean or optionset attributes.

Attribute Types: Boolean, optionset
.getIsDirty()
Returns a Boolean value indicating if there are unsaved changes to the attribute value.
.getMax()
Returns a number indicating the maximum allowed value for an attribute.

Attribute Types: money, decimal, integer, double

Useful JavaScript commands for Microsoft CRM 2011 - Part 1: Xrm.Page.context

Useful JavaScript commands for Microsoft CRM 2011 - Part 1: Xrm.Page.context
Xrm.Page.context – provides methods to obtain information specific to the organization, user or parameters that were passed in the form of a query string.
Command

Description
.getAuthenticationHeader()
Returns the encoded header SOAP-request for Web service in the style of MSCRM 4.0.
.getCurrentTheme()
Returns the current user's Outlook theme.
.getOrgLcid()
Returns the value of the LCID for the main language of the organization.

Example:
Xrm.Page.context. getOrgLcid();
.getOrgUniqueName()
Returns the unique name of the organization.
.getQueryStringParameters()
Returns an array of key-value pairs passed in the query string.
.getServerUrl()
Returns the base server URL. When a user is working offline with Microsoft Dynamics CRM for Microsoft Office Outlook, the URL is to the local Microsoft Dynamics CRM Web services.
.getUserId()
Returns the GUID value of the SystemUser.id value for the current user.

Example:
Xrm.Page.context.getUserId();
.getUserLcid()
Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.

Example:
Xrm.Page.context.getUserLcid();
.getUserRoles()
Returns an array of strings representing the GUID values of each of the security roles that the user is associated with.

Example:
Xrm.Page.context.getUserRoles();
.isOutlookClient()
Returns a Boolean value indicating if the user is using Microsoft Dynamics CRM for Microsoft Office Outlook.

Example:
Xrm.Page.context.isOutlookClient();
.isOutlookOnline()
Returns a Boolean value indicating whether the user is connected to the Microsoft Dynamics CRM server while using Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access. When this function returns false, the user is working offline without a connection to the server. They are interacting with an instance of Microsoft Dynamics CRM running on their local computer.

Example:
Xrm.Page.context.isOutlookOnline();
.prependOrgName()
Adds the name of the organization to the specified path.

Friday, September 23, 2011

How to add color to a Microsoft CRM 2011 Form Picklist

Add color to target picklist is a very simple task. I will show you an example on Task form, Priority Picklist.
It has three options: Low, Normal, High.
Let’s add colors for them: Yellow, Green and Red.

Simply add OnLoad event:

function AddColorToPriority()
{
crmForm.all["prioritycode"][0].style.background = "#FFF380"; // Low => Yellow
crmForm.all["prioritycode"][1].style.background = "#5EFB6E"; // Normal => Green
crmForm.all["prioritycode"][2].style.background = "#E55451"; // High => Red
}


Here is other way to implement it:

function AddColorToPrioritySecond()
{
crmForm.all.prioritycode[0].style.background = "yellow"; // Low => Yellow
crmForm.all.prioritycode[1].style.background = "green"; // Normal => Green
crmForm.all.prioritycode[2].style.background = "red"; // High => Red
}

Monday, September 19, 2011

Get a list of System and User Dashboards in CRM 2011

You can get a complete list of System and User Dashboard by:

public void InitializeDashboardList()
{
     this.GetSystemDashboard();
     this.GetUserDashboard();
}

private void GetSystemDashboard()
{
if (!User.HasPrivilege("systemform", AccessRights.ReadAccess, (IOrganizationContext)UserInformation.Current))
return;
var systemdashboard = this.RetrieveDashboard("systemform", new string[4]
{
"formid",
"name",
"isdefault",
"description"
});
}

private void GetUserDashboard()
{
if (!User.HasPrivilege("userform", AccessRights.ReadAccess, (IOrganizationContext)UserInformation.Current))
return;
var userdashboard = this.RetrieveDashboard("userform", new string[3]
{
"userformid",
"name",
"description"
});
}

private ApplicationEntityCollection RetrieveDashboard(string logicalName, string[] columns)
{
     QueryExpression query = new QueryExpression(logicalName);
     query.ColumnSet.AddColumns(columns);
     query.Criteria.AddCondition("type", ConditionOperator.Equal, (object)0);
     query.Orders.Add((object)new OrderExpression("name", OrderType.Ascending));
     return DataSource.RetrieveMultiple(query, (IOrganizationContext)UserInformation.Current);
}

List of Microsoft CRM 2011 Web Services

List of Web Services:

http://demo:7777/AppWebServices/ActivitiesWebService.asmx

http://demo:7777/AppWebServices/AdvancedFind.asmx

http://demo:7777/AppWebServices/Annotation.asmx

http://demo:7777/AppWebServices/AppGridWebService.asmx

http://demo:7777/AppWebServices/AssociateRecords.asmx

Wednesday, September 14, 2011

Search all columns of all tables in a MS CRM 2011 database for a keyword.


Here is the complete stored procedure code:
CREATE PROC SearchKeywordInAllCRMTables
(
@SearchKeyword nvarchar(100)
)
AS
BEGIN

CREATE TABLE #SearchResults (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @TempKeyword nvarchar(110)

Wednesday, September 7, 2011

Add specific access Role for Dashboard in the CRM 2011.


First we need to find out RoleID. To do that simply run Microsoft SQL Management Studio and execute following query:

SELECT [Name],[RoleIdUnique] FROM [OrganizationName_MSCRM].[dbo].[Role]

You will get something like:

Thursday, August 25, 2011

Create first plugin with Development Toolkit CRM 2011 Part 1.


Before we begin, let's create some additional entities. I want to create “Meeting” and “Resources” entities.
Entity Meeting should represent information about meeting, invited participants and needed resources. Meeting form should include such fields:
  • Meeting Name.
  • Location. 
  • Start date. 
  • End date. 
  • Description. 
  • Priority. 
  • Send Email to participant.


Also it should have 1:N relation to Contacts and Resources.
Entity Resources describes information about resources that are involved in the meeting. (Example: Projector, Microphones, Speakers and etc.)
Resources form should include such fields:
  • Name.

Get string value of OptionSet in CRM 2011

If you need to retrieve StateCode or StatusCode or other OptionSet of attribute, then simply use code bellow:


public static OptionMetadataCollection GetOptionsSetByAttribute(IOrganizationService service, string entityName, string attributeName)
{

var retrieveAttributeRequest = new RetrieveAttributeRequest();
retrieveAttributeRequest.EntityLogicalName = entityName;
retrieveAttributeRequest.LogicalName = attributeName;
retrieveAttributeRequest.RetrieveAsIfPublished = true;

var retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);

var optionMetadataCollection = (((StatusAttributeMetadata) retrieveAttributeResponse.AttributeMetadata).OptionSet).Options;

//foreach (OptionMetadata optionMetadata in optionMetadataCollection)
//{
// Here you can add your advanced logic.....
// optionMetadata.Label.UserLocalizedLabel.Label = "Teset";
//}
// or simply return OptionMetadataCollection....
return optionMetadataCollection;

}

To use it just write:
OptionMetadataCollection metadatas = GetOptionsSetByAttribute(this.OrganizationService, "new_cars", "statuscode");   

Tuesday, August 23, 2011

Developing with Development Toolkit CRM 2011


You need to download and extract last CRM 2011 SDK.  In \sdk\tools\developertoolkit\ run crmdevelopertools_installer.msi to install toolkit.


First we need to create a New Project:  File -> New Project or press Ctrl+Shift+N 
In Dialog windows select Dynamics CRM Template and New Visual Studio Solution Template for Dynamics CRM 2011.
Enter a Name and Solution name.

Saturday, August 20, 2011

CRM 2011 Maintenance Job Editor

CRM 2011 Maintenance Job Editor - it has evolved from CRM 4.0 ScaleGroup Job Editor tool for working with CRM 2011. This utility is used to edit the schedule jobs to run services, such as rebuilding indexes, cleaning jobs workflow, etc.

Service jobs are assigned to the same time, the organization which is created in the CRM 2011. For example: You have created an organization at 13:00, then the job will run services for the organization every 24 hours, at 13:00. And that could create an additional load on the system that adversely affect your system's performance in "rush hour".

To use this utility, download it and copy the two files in the folder "C: \ Program Files \ Microsoft Dynamics CRM \ Tools" and run the EXE-file. Don't forget to play with the settings.

Thursday, August 11, 2011

SoapLogger

SoapLogger - is a console application (Visual Studio 2010) came with the CRM 2011 SDK, which allows you to receive the formatted SOAP requests and responses that you send through the code to the endpoint SOAP CRM 2011.

Uses:
Download and unzip the CRM 2011 SDK;
Open the project \ SampleCode \ CS \ Client \ SOAPLogger \ SOAPLogger.sln;

First Post.

Hello This is my first blog dedicated to MS CRM 2011. Here I will describe all the interesting things that are associated with MS CRM 2011.