Using alias for link entity attributes in MS CRM

We can read link entity attributes by aliasing link entity or attributes. Here we will be discussing second point.

It is as simple as keeping alias attribute for each field with alias name. Here important note is , if you give alias name is same as filed or attribute name as shown below fetchXML, you don't need to type cast with "AliasedValue" to read this field. You can read the value direclty how you read parent attributes.




<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='new_workorder'>
       <attribute name='new_name' />
       <order attribute='new_name' descending='false' />
       <link-entity name='incident' from='incidentid' to='new_workorderid' visible='false' link-type='outer' alias='a'>
           <attribute name='new_incidentnumber' alias='new_incidentnumber' />
       </link-entity>
     </entity>
 </fetch>

Here you can read "new_incidentnumber" field with any type casting to AliasedValue.



string incidentNumber = Convert.ToString(entityCollection.Entities[0].Attributes["new_incidentnumber"]);
If you give alias name as different than field name then we should type cast with AliasedValue to read its value.










Merge assemblies using ILMerge

Sometimes we do have requirement of using external dll in a plugin. So, to register our plugin we should merge it to make a single dll. Here we will be using ILMerge for merging the dlls. ILMerge is an utility which merges multiple .NET assemblies into a single assembly.

Download ILMerge utility here

Syntax:
Ilmerge.exe [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysign]] [/internalize[:filename]] [/target]:(library|exe|winexe)] [/closed] [/debug] [/ver:version] [/copyattrs [/allowMultiple]] [/xmldocs] [/attr:filename] ([/targetplatform:<version>[,<platformdir>]]|v1|v1.1|v2|v4) [/useFullPublicKeyForReferences] [/zeroPeKind] [/wildcards] [/allowDup[:typename]]* [/allowDuplicateResources] [/union] [/align:n] /out:filename <primary assembly> [<other assemblies>...]

Out of all the options we basically use four major options to merge , below is the sample example for ILMerge.

ILMerge.exe /out:"C:\ILMerge\Primary.dll" /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319" /targetplatform:"v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319" /keyfile:"Your path to .snk file" "C:\Main\Primary.dll" "C:\Main\Secondary.dll"

/out:  This must be set before calling Merge. It specifies the path and filename that the target assembly will be written to.

/lib: If specified, this sets the directories to be used to search for input assemblies. We do set the path for .Net Framework 4.0.

/targetplatform: This method sets the .NET Framework for the target assembly to be the one specified by platform. Valid strings for the first argument are "v1", "v1.1", "v2", and "v4". The "v" is case insensitive and is also optional. This way ILMerge can be used to "cross-compile", i.e., it can run in one version of the framework and generate the target assembly so it will run under a different assembly. The second argument is the directory in which mscorlib.dll is to be found

/keyfile: When this is set before calling Merge, it specifies the path and filename to a .snk file. The target assembly will be signed with its contents and will then have a strong name

What are activity entites in MS CRM

Activities are tasks that you or your teams perform when they contact customers, for example, sending letters or making telephone calls. You can create activities for yourselves, can assign them to someone else, or can share them with other users or teams. An activity is any action which can be entered on a calendar and has time dimensions (start time, stop time, due date, and duration) that help determine when the action occurred or is to occur. 

As per business requirements we can create our own custom activity entity. And, we can create 1:N relationship with any other entities as just like normal entity.

Below are the list of features available for  activity entity.


  1. It has default offline availability.
  2. Mail merge is disabled for activity entity.
  3. Activity entity ownership can be either team-owned or user-owned. You cannot set it as organization level.
  4. You cannot display activity entity in sales, marketing or any other areas.
  5. By default Feedback, Notes,  Connections and Queues are enabled by default we cannot change them.
  6. Knowledge management cannot be enabled.
  7. By default primary field for activity entity is subject which is a single line of text with 200 max length. We cannot change it.
  8. A custom activity entity must not have relationships with activities.

Html encode or decode online



           

Actions on entity records

Each entity supports several records like create, update, delete or assign a record to team or user,. But not all actions are allowed on all entity or attributes. We need to verify IsValidForCreate, IsValidateForUpdate or IsValidateForDelete fileds values to check to know whether we can perform create, update or delete operations on that entity or attributes.

Below are the list of actions we do perform on entity records.


Create
To create a record in an entity
Update
To update an attribute or attributes of a records
Delete
To delete a record
Retrieve
To retrieve a record of an entity
To retrieve collection of records
Assign
Changes ownership of a record
Share
Grant, modifies or revoke access to a record
To create a link between a record and collection of records between related entities
To remove a link between a record and collection of records between related entities
To set the state of a record

Relationships between entities

We can build three types of relationships between entities.

  1. One-to-many
  2. Many-to-One
  3. Many-to-many

I would like explain these relationships with an example. Assume there are two entities called A and B. As per the requirement A record can contains more than one B records, that means we need to create a one-to-many relationship between A and B, once you create the relationship, one A entity related lookup field will be created automatically in B entity. So, for each record you are creating in B entity you will selecting the respective A entity related record. One each record of A entity, you can see all the associated records of entity B in associated view.

Many-to-one is same as One-to-many if we are following above process from B to A.


The records for a many-to-many relationships are stored in an intersect entity which contains the ID of both the referenced and referencing records. In Many to many relationships we need to establish a link between records by associate or disassociate.


What is an entity in MS CRM

Entity in MS CRM used to manage business data. In simple terms we can refer entity as Table in database, and, each record in an entity can refer as a row in a table. And, each field in an entity can refer as a column in table.

There are three types of entities in MS CRM.

1. System
2. Business
3. Custom

As a developer, you will be dealing with Business and custom entities. System entites are purely internal usage of CRM. We cannot customize or delete system entites. Examples for system entities are workflows and asynchronous jobs etc.

Business entities are default entities CRM provide while installing. Examples for business entities are Contact, Account, Case etc.

Custom entities are entities which we will be create as per business requirement.. 

Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...