Classifying Accounts with Many-to-Many Relationships
Sometimes a single-valued picklist is sufficient to classify records like accounts in Dynamics CRM, but sometimes it's not. In this video I talk about why and how you might want to use many-to-many -- N:N for short -- relationships, and demonstrate how to implement them in Dynamics CRM 2011.
Associate Records In Microsoft Dynamics CRM Using Early Bound
To associte records in Microsoft Dynamics CRM use IOrganizationService.Associate(entityName, Guid, Relationship, EntityReferenceCollection) method.
Entity logical name
The ID of the record to which the related records are associated.
The name of the relationship to be used to create the link.
A collection of entity references (references to records) to be associated..
This method is implemented by OrganizationService class and OrganizationServiceContext generated in previous chapter.
Using Early Bound
Following example demonstarates how to associate a contact with three accounts in Microsoft Dynamics CRM using early bound
// Associate the accounts to the contact record.
// Create a collection of the entities that will be
// associated to the contact.
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account1Id));
relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account2Id));
relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account3Id));
// Create an object that defines the relationship between the contact and account.
Relationship relationship = new Relationship("account_primary_contact");
//Associate the contact with the 3 accounts.
_service.Associate(Contact.EntityLogicalName, _contactId, relationship,
Console.WriteLine("The entities have been associated.");
//Disassociate the records.
_service.Disassociate(Contact.EntityLogicalName, _contactId, relationship,
• Should be able to create and debug Plugins - Should be able to create and debug Custom Workflow activities
• Should be able to do Ribbon customization - Understanding of Solutions - Understanding of the security in Dynamics CRM
• Should have understanding of using Developer Toolkit for Dynamics CRM
Good to have:
• Strong design and development skills
• Ability to design and develop flows
• Effectively communicates to internal and external stake-holders"
Full Time Graduation
Processes/Workflow Ownership Mystery in Microsoft Dynamics CRM
Under what user’s context does the workflow execute? (If the workflow creates a record, who will be the owner of that new record?)
It depends. Automatically triggered workflows (such as a workflow that triggers on account create) will execute in the context of the owner of the workflow. Therefore, if you have a send email step, the email will be by default sent from the e-mail account of the workflow owner. This is important to consider because the workflow owner might belong to a different business unit and have different privileges than the user who triggered the workflow (e.g. who created the account). Let’s say your workflow creates a task each time an account is created. Depending on the privileges of the user, the task might be in another business unit and not visible to the user, therefore you should consider adding an “assign step” that assigns the new task to the owner of the account. Now, if the workflow is executed on-demand, the workflow will then execute in the context of the user who requests the workflow execution. Because dialogs are always on-demand then they always execute in the context of the user who started the dialog.
Why does the process execute under different users depending on how it was started?
This was a design decision based on security considerations. You don’t want to inadvertently be sending emails and executing actions without knowing it because some other user decided it. Therefore, by having this different behavior we can guarantee that the user under which the workflow executes is always aware that a workflow is performing some actions on his behalf. For the automatic workflow case, the owner of the workflow is also the person who activates it and who selects the trigger mechanism and the workflow steps so it is OK if the workflow executes under that user’s context. For the on-demand case, a user is specifically requesting some actions to be performed on his behalf by a workflow so the user is fully aware of the workflow definition and that it will execute; therefore it is safe to execute the workflow under that user’s context instead of the workflow owner (who might not be aware that a user requests an on-demand execution).
Why can’t I activate/deactivate someone else’s workflow, even if I am the system administrator?
For the same security reason as explained above. You want the workflow owner to explicitly acknowledge that a workflow will be activated and will perform some actions on his behalf. You would not want to allow another user (even the system administrator) to decide that some process should be executed on another user’s behalf. If you want to activate/deactivate someone else’s process you must first assign it to yourself.
If I assign an activated process to another user, why does the user have to re-activate it?
Active processes cannot be modified so the system automatically deactivates them before assigning it to the new user. As per Q3 above, only the new owner will be able to re-activate the process.
I am importing a solution that contains processes and it fails with this error message “The workflow cannot be published or unpublished by someone who is not its owner”. What is wrong?
If your solution contains a process that already exists in the organization and is activated then solution import will attempt to update it. In order to do so, it must first deactivate it. However, if the owner of the activated process is not the same as the user who is importing the solution, then deactivating the process will fail (see Q3). Therefore you have a few options to fix this problem:
Import the solution using the user who owns the activated process. This can be tricky, especially if there are multiple processes owned by different users which need to be updated by the solution import.
Verify which processes are included in the solution, and then find them in the organization, if you can find them and they are not owned by you then you must assign them to yourself. You can reassign them to the original user after you import the solution; however, you will have to ask the process owners to activate it themselves.
Discovery Web Service in Microsoft Dynamics CRM
Discovery Web Service
The Discovery web service is used to determine the organizations that a user is member of, and provides the Organization service endpoint URL for each of those organizations which is further used to connect to specific organization.
It is required because Microsoft Dynamics CRM is a multi-tenant application i.e. a single deployment can host multiple instances of CRM.
Key points about Discovery service
It implements IDiscoveryService interface.
It is built on Window Communication Foundation (WCF).
It can provide information such as
Organization friendly name
Unique id of organization
Current state (disabled or enabled)
Discovery service usage:
To determine the organizations a user is member of in a muti-tenant environment.
To determine the endpoint urls of those organizations.
In a data center server details of organizations can change because of maintenance or load balancing, therefore hard-coding organization url is removed.
Discovery service endpoint URLs:
The following table lists the Web service URLs for the worldwide Microsoft Dynamics CRM Online data centers.
The <CommandDefinition> (RibbonDiffXml) element defines a command in the ribbon. The Id attribute specifies a unique identifier for the command that can be referenced by ribbon control elements by using the Command parameter.
A ribbon command defines three things:
Enable Rules: Specifies when a specific ribbon control will be enabled.
When configuring Ribbon elements you can define specific rules to control when the ribbon elements are enabled. The <EnableRule> (RibbonDiffXml) element is used as follows:
Use the /RuleDefinitions/EnableRules/EnableRule element to define rules controlling when the ribbon element should be enabled.
Use the /CommandDefinitions/CommandDefinition/EnableRules/EnableRule element to associate specific enable rules to a command definition.
Display Rules: Specifies when a specific ribbon element will be visible.
When configuring ribbon elements, you can define specific rules to control when the ribbon elements will display.
Use the /RuleDefinitions/DisplayRules/<DisplayRule> (RibbonDiffXml) element to define rules controlling when the ribbon element should be displayed.
Use the /CommandDefinitions/CommandDefinition/DisplayRules/<DisplayRule> (RibbonDiffXml) element to associate specific display rules to a command definition.
Actions: Specifies what code will execute when a ribbon control is uses.
Define the actions to be performed by a ribbon control in a <CommandDefinition> (RibbonDiffXml) element together with rules that control whether the control is enabled or visible in the ribbon.
A Ribbon control can perform two types of actions and may include multiple actions:
Open a URL: The ribbon opens a URL using the value from an Address attribute in the <Url> (RibbonDiffXml) Additional parameters can pass information about how what querystring parameters are passed and the mode in which the window opens. You have several options to pass parameters to a URL using the ribbon. For more information, see Pass Parameters to a URL By Using the Ribbon.
Generate early bound entity classes with the code generation tool (CrmSvcUtil.exe)
CrmSvcUtil.exe is a command line tool which can generate early bound classes for Microsoft Dynamics CRM. Output file can be C# or VB.Net file.
Generated file contains
All entities, one partial class for each entity
These strongly typed classes provide early binding and Intellisense support in Microsoft Visual Studio.
Generated file can be referenced by projects that use Microsoft Dynamics CRM. Following assemblies must also be referenced in that project
These assemblies can be found in SDK\bin folder of the SDK.
Running code generation tool
Make sure Microsoft.Xrm.Sdk.dll assembly is in same folder.
To list the supported command-line parameters, use the following command.
The following table lists the code generation tool parameters and a gives a brief description of their use.
Device ID used when you connect to the Online server for authentication. Only required if the device ID has not been stored on disk in the %USERPROFILE%\LiveDeviceID folder. Only used with the Microsoft account identity provider.
Device password that is used when you connect to the Online server for authentication. Only required if the device password has not been stored on disk in the %USERPROFILE%\LiveDeviceID folder. Only used with the Microsoft account identity provider.
The domain to authenticate against when you connect to the server.
The URL for the Organization service.
The file name for the generated code.
The language to generate the code in. This can be either “CS” or “VB”. The default value is “CS”.
The namespace for the generated code. The default is the global namespace.
The user name to use when you connect to the server for authentication.
The password to use when you connect to the server for authentication.
The name of the generated organization service context class. If no value is supplied, no service context is created.
Show usage information.
Suppress the banner at runtime.
Generate request and response classes for actions.
When set to true, a dialog to log into the CRM service is displayed. All other connection related parameters specified on the command line are ignored.