Pages

Thursday 25 July 2013

CRM 2011: Signing the Plug-in Assembly

Only signed plug-in assemblies are allowed to be registered on Microsoft Dynamics CRM 2011.

To sign an assembly with a strong name, it must have a public/private key pair.

The assembly can be signed using
  • Microsoft Visual Studio, OR
  • Strong Name Tool (sn.exe)

Using Microsoft Visual Studio (UI)

Follow these steps to sign the assembly using Microsoft Visual Studio 2010
  1. Right-click the project and click "Properties".
  2. Select "Signing".
  3. Check "Sign the assembly".
  4. Select an existing key or create a new one.
  5. Save the properties.
  6. Rebuild the DLL.

Using Strong Name Tool (sn.exe)

  1. Open Visual Studio 2010 Command Prompt
  2. Run the command, sn -k [filename]

Refer to Microsoft's documentation for more information.

Monday 22 July 2013

CRM 2011: Limited/reduced functionality of Sandboxed plug-ins

Microsoft recommends running plug-ins in a sandbox mode. The plug-ins running in a sandboxed environment have reduced functionality to ensure security.

The following network access restrictions apply to this sandbox capability.

  • Only HTTP and HTTPS protocols are allowed.
  • Access to localhost is not permitted.
  • Plug-ins must rely on DNS name resolution (using a named web address).
  • Anonymous authentication is recommended and supported by Microsoft.
  • .NET framework classes can be used in the plug-in code to access web resources considering previously outlined restrictions.
Refer to Microsoft's documentation for further information.

Monday 15 July 2013

CRM 2011: Plug-in Isolation(Sandbox), Trusts and Statistics

Plug-in Isolation (Sandbox Mode)

Microsoft Dynamics CRM 2011 supports the execution of plug-ins in an isolated environment, also known as Sandbox.

A Sandbox plug-in can access
  •  Microsoft Dynamics CRM SDK web services
  • External endpoints just as Windows Azure cloud and other common web services
and CANNOT access the following
  • File system
  • System event log
  • Network and more 
The execution of plug-ins in a sandbox mode is recommended by Microsoft because 
  • It is more secure
  • It supports run-time monitoring and statistics reporting
  • It is supported for all Microsoft Dynamics CRM deployments

Full and Partial Trusts

Plug-ins can be registered
  • In the sandbox mode, known as partial trust
  • Outside the sandbox mode, known as full trust
The table illustrates the deployment types and the supported trust level.






Run-time Statistics  

The Microsoft Dynamics CRM platform collects run-time statistics and also monitors the plug-ins that execute in a sandbox mode. If sandbox worker process exceeds the threshold utilisation of resources or is unresponsive then the CRM platform ends the process, this won't impact the other organisations because each organisation has its own sandbox worker process. This information is stored in the database table "PluginTypeStatistic". 



Friday 12 July 2013

CRM 2013: Orion - Screenshots

CRM 2013 - Orion (Application Screenshots)


CRM 2013 - Orion (Mobile Screenshots)


Credits: North52

CRM 2011: Workflow Activity Input and Output Parameters & Data Types

Microsoft Dynamics CRM supports two types of parameters for a workflow activity.
  • Input Parameters
  • Output Parameters

Input Parameters

The input parameter is annotated with the .NET attribute "Input".


DefaultAttribute

DefaultAttribute class can be used to specify a default value (using "Default" attribute) for an input parameter. 


Bool

[Input("Bool input")]
[Output("Bool output")]
[Default("True")]
public InOutArgument<bool> Bool { get; set; }


DateTime

[Input("DateTime input")]
[Output("DateTime output")]
[Default("2013-07-09T02:54:00Z")]
public InOutArgument<DateTime> DateTime { get; set; }


Decimal

[Input("Decimal input")]
[Output("Decimal output")]
[Default("20.75")]
public InOutArgument<decimal> Decimal { get; set; }


Double

[Input("Double input")]
[Output("Double output")]
[Default("200.2")]
public InOutArgument<double> Double { get; set; }


Integer

[Input("Int input")]
[Output("Int output")]
[Default("2322")]
public InOutArgument<int> Int { get; set; }


Money (Currency)

[Input("Money input")]
[Output("Money output")] 
[Default("232.3")]
public InOutArgument<Money> Money { get; set; }


OptionSetValue

[Input("OptionSetValue input")]
[Output("OptionSetValue output")]
[AttributeTarget("account", "industrycode")]
[Default("3")]
public InOutArgument<OptionSetValue> OptionSetValue { get; set; }
Attribute Target must specify the entity and attribute being referenced. 


String

[Input("String input")]
[Output("String output")]
[Default("string default")]
public InOutArgument<string> String { get; set; }


Entity Reference

[Input("EntityReference input")]
[Output("EntityReference output")]
[ReferenceTarget("account")]
[Default("3B036E3E-94F9-DE11-B508-00155DBA2902", "account")]
public InOutArgument<EntityReference> AccountReference { get; set; }
Reference Target attribute must specify the type of entity being referenced. 


Required Argument Attribute 

System.Activities.RequiredArgumentAttribute class can be used to specify that the input parameter is required.

[RequiredArgument]
[Input("Update next Anniversary date for")]
[ReferenceTarget("contact")]
public InArgument<EntityReference> Contact { get; set; }


Output Parameters

The output parameter is annotated with the .NET attribute "Output"

//this is the name of the parameter that will be returned back to the workflow
[Output("Credit Score")]
//this line identifies the specific attribute which will be passed back to the workflow
[AttributeTarget(CustomEntity, "new_creditscore")]
//this line declares the output parameter and declares the proper data type of the parameter being passed back.
public OutArgument<int> CreditScore {get;set;}

Refer to Microsoft documentation for more details

Tuesday 9 July 2013

Monday 8 July 2013

CRM 2011: Client-side (forms, fields, tabs and IFrame) events in Microsoft Dynamics CRM 2011

1. Form Events

There are two events at the form level in Microsoft Dynamics CRM 2011
  • OnLoad Event
  • OnSave Event

OnLoad Event

The OnLoad event occurs after the form has been loaded. Normally OnLoad event is used to apply logic relevant to user interaction like
  • Display/Hide components on the form
  • Enable/Disable components on the form
  • Alert users of a specific business situation 
  • Perform calculations/actions using web service calls etc.

OnSave Event

OnSave event occurs after the form is saved. Normally following actions cause the form to be saved
  • User clicks the "Save" button
  • User clicks the "Save and Close" button
  • Other actions also cause the form to be saved, the Save method in the JavaScript
    • Xrm.Page.data.entity.save( null | "saveandclose" |"saveandnew" )
    • save() - if no parameter is included then it simply saves the record
    • save("saveandclose") - save and close the record form
    • save("saveandnew") - save current record and open new record form
OnSave event is commonly used for data validation or to perform a specific operation using web services.

The OnSave event can also be cancelled to prevent the data from being saved, following JavaScript code can be used to cancel the save operation.

event.returnValue = false;
return false;

2. Field Events

OnChange Event

OnChange event is available for every field on the form. The OnChange event triggers when the following two actions occur
  • The field data changes AND
  • The field loses focus
This event is commonly used to do the following
  • Display/Hide components on the form
  • Mark other fields mandatory or non-mandatory based on this field's value
  • Implement dynamics option sets
  • Perform calculations/actions using web service calls to change other fields based on changing values
  • formatting (e.g phone field)
OnChange event can also be triggered by invoking FireOnChange method for a specific field.

3. Tab Events

TabStateChange Event

TabStateChange event occurs when a tab is expanded or collapsed, implementing this event can defer the execution of code until a tab state is changed.


4. IFRAME Events

OnReadyStateComplete Event

OnReadyStateChange event is the indication that the contents of the IFRAME has been loaded and are available to be accessed in the script. If the script interacts with the IFRAME contents before they are fully loaded, the script will fail.


Saturday 6 July 2013

CRM 2011: Share/Unshare records with a Team or a User using CRM SDK, C#


Sharing and Unsharing records with a Team using Microsoft Dynamics CRM 2011 SDK (early bound classes). You can also do a slight modification to use this code for sharing records with specific users.

Share Record with Team - Read only Access

public static void TeamShareWithReadAccess(IOrganizationService service, Guid recordId, string recordEntityName, Guid teamId)
        {
            GrantAccessRequest grantAccessRequest = new GrantAccessRequest()
            {
                Target = new EntityReference(recordEntityName, recordId),

                PrincipalAccess = new PrincipalAccess()
                {
                    Principal = new EntityReference(Team.EntityLogicalName, teamId),
                    AccessMask = AccessRights.ReadAccess,
                }
            };

            GrantAccessResponse grantAccessResponse = (GrantAccessResponse)service.Execute(grantAccessRequest);
        }

Share Record with Team - Read-Write Access (+Share, Assign, Append and AppendTo access)

public static void TeamShareWithReadWriteAccess(IOrganizationService service, Guid recordId, string recordEntityName, Guid teamId)
        {
            GrantAccessRequest grantAccessRequest = new GrantAccessRequest()
            {
                Target = new EntityReference(recordEntityName, recordId),

                PrincipalAccess = new PrincipalAccess()
                {
                    Principal = new EntityReference(Team.EntityLogicalName, teamId),
                    AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess | AccessRights.ShareAccess | AccessRights.AssignAccess | AccessRights.AppendAccess | AccessRights.AppendToAccess,
                }
            };

            GrantAccessResponse grantAccessResponse = (GrantAccessResponse)service.Execute(grantAccessRequest);
        }

Revoke Shared Access from Team

 public static void RevokeTeamShare(IOrganizationService service, Guid recordId, string recordEntityName, Guid teamId)
        {
            RevokeAccessRequest revokeAccessRequest = new RevokeAccessRequest()
            {
                Target = new EntityReference(recordEntityName, recordId),
                Revokee = new EntityReference(Team.EntityLogicalName, teamId)
            };

            RevokeAccessResponse revokeAccessResponse = (RevokeAccessResponse)service.Execute(revokeAccessRequest);
        }

Friday 5 July 2013

CRM 2011: Auditing Features


Why Need Auditing ?

Microsoft Dynamics CRM 2011 offers auditing features and there are many reasons for an organisation wanting to audit business data.

 Some are:

  • Analyse user actions to improve business processes
  • For maintaining history of the business data
  • To comply with legal regulations
  • To maintain security

Levels of Auditing 

There are three levels of Auditing in Microsoft Dynamics CRM 2011
  • Organisation
  • Entity
  • Field

Supported Features

  • Organisation Level
    • Audit of Areas (Sales, Marketing, Service)
    • Audit of audit events
    • Audit log deletion
  • Entity Level
    • Audit of custom and customizable entities
    • Audit of create, update and delete events of records
    • Audit of changes to the shared privileges of a record
    • Audit of relationships (1:N, N:1, N:N) - Associations or disassociations
    • Audit of privilege changes (changes to security roles)
  • Field Level
    • Audit of fields of custom and customizable entities
    • Audit of update event of fields

Unsupported Features

  • CRM cannot audit/log who reads data and when
    • this includes reading data on forms, views, reports and data exports
  • CRM cannot audit/log changes to metadata, for example renaming a field

Key Concepts

  • Auditing can be enabled at Organisation, entity and field levels. CRM will  ONLY start auditing the data when auditing is enabled at the Organisation level (enabling at entity and field level will not start auditing)
  • Audit data is stored in a database table, it is not represented as an entity within the Organisation
  • Audit data is divided logically into quarterly segments called "Audit Logs", Audit Logs can be individually deleted to free up some space.

Audit Permissions

Only System Administrator and/or System Customizer has rights to enable or disable Auditing at the Organisation level.

Other auditing permissions which can be granted by configuring security roles
  • View Audit Partitions
  • Delete Audit Partitions
  • View Audit History
  • View Audit Summary
Refer to Microsoft's documentation for more information.

Tuesday 2 July 2013

CRM 2011: JavaScript to refresh CRM form ribbon & form controls using Xrm.Page Object Model

JavaScript to refresh CRM form ribbon & form controls using Xrm.Page Object Model

Xrm.Page Object Model should be used to refresh ribbon and controls on the CRM form.

Refresh Ribbon

refreshRibbon() method should be used to refresh form ribbon. Normally this code snippet is used to refresh(re-evaluate) ribbon to enable/disable or show/hide ribbon components when the data is changed on the form.
Xrm.Page.ui.refreshRibbon();

Refresh SubGrid


Following code snippet can be used to refresh data in the SubGrid.

Xrm.Page.getControl("accountcontactsgrid").refresh();

CRM 2011: JavaScript to close CRM form using Xrm.Page Object Model

JavaScript to close CRM form using Xrm.Page Object Model

Xrm.Page.ui.close();

The HTML Window.close() method is suppressed and should not be used to close CRM form.