Thursday, 10 December 2015

All about Plugins

Q. What is Execution Order in Plug-in Registration tool?


Execution order in plugin specifies the order in which plug-ins are executed within a pipeline stage. Plug-ins registered with an order value of 1 are executed first, followed by plug-ins registered with an order of 2, and so on. However, if there is more than one plug-in in a stage with the same order value, then the plug-in with the earliest compilation date is called first



What is the difference between PreImage, PostImage, Target Entity?

In a plug-in there are potentially several ways to access entity data relevant to the plug-in action. For example, on the create message you can access the data on the new entity instance in one of the following ways:
  1. Via the Target InputParameter
  2. Via an Image Entity registered on the step
Via a Retrieve request in the plug-in code


Availability of the data by stage
The general rules are:
1.       InputParameter is available in all stages. It can be modified in the pre-stage, but changing it in the post-stage will have no effect
2.       A PostImage Entity is available in the post-stage, and a PreImage Entity in the pre-stage only
3.       If using a Retrieve in the plug-in, then the data returned depends on the stage. In the pre-stage, you will see the data before the modification, whereas in the post-stage you see the data after the modification
4.       Some Image Entities are not relevant for some messages - e.g. there is no PreImage for a Create message, and no PostImage for a Delete message




1. All the plug-in events are first stored in  variable called “Target”.
Target  entity available on all steps and contains entity passed in the request message. Target entity can update on Pre-stage and those changes will be post into the database. Changes on Post-stage don’t affect database.

2. Pre-image, you get the image of the record as is stored in the SQL database before the CRM Platform action has been performed.
Post Image, returns the image of the record after the CRM Platform action has been performed. 

PreEntityImages and PostEntityImages contain snapshots of the primary entity's attributes before and after the core platform operation. Following tables describes PreImage, PostImage availability:



Pre-Image
Post-Image
Pre
Post
Pre
Post
Create
No
Yes
No
Yes
Update
Yes
Yes
No
Yes
Delete
Yes
Yes
No
No


Note. Target entity only contains attributes platform needs to update.

Friday, 4 December 2015

JavaScript in MS CRM 2013/2015

Get current entity name

var entity = Xrm.Page.data.entity.getEntityName();

Disable the field


Xrm.Page.getControl("telephone1").setDisabled(true);

Hide field

Xrm.Page.getControl("telephone1").setVisible(false);

Get value from one field and set to other field

var phone = Xrm.Page.getAttribute("telephone1").getValue();
    
        Xrm.Page.getAttribute("fax").setValue(phone);

Get Current User Role

Xrm.Page.context.getUserRoles();

Hiding tab
Xrm.Page.ui.tabs.get(tabindex).setVisible(false);
or
Xrm.Page.ui.tabs.get("tabname").setVisible(false);

Showing tab
Xrm.Page.ui.tabs.get(tabindex).setVisible(true);
or

Xrm.Page.ui.tabs.get("tabname").setVisible(true);

Thursday, 3 December 2015

Create Custom entities in MS Dynamics CRM 2015 online


  1. On the  navigation pane of CRM, click on the Settings --> Customizations --> Customize the system(Also can proceed from custom solution)
  2. Click the Entities node in the solution explorer and then click New in the menu bar.

3. Complete all required fields Display Name, Plural Name and Name.


    


4. Select whether the entity will be owned by a user or team/organization

5. Select Areas that display this entity section, select Sales and Marketing.

6. Click Save and Close to close the new entity form.

7. Publish the customization. Entity will be seen under Sales and Marketing.

Wednesday, 2 December 2015

Show MS CRM Account details in grid view of Asp.net

Hi,

Here is a code to show account details from Dynamics CRM online 2015 to gridview of ASP.Net through late binding.

Add new web form and add one gridview to design form.

 Now add code to code view.

protected void Page_Load(object sender, EventArgs e)
        {
            IOrganizationService service = GetCRMService();
            QueryExpression query = new QueryExpression("account");
            query.ColumnSet.AllColumns = true;
            EntityCollection ecollection = service.RetrieveMultiple(query);

            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            dt.Columns.Add("accountid");

            foreach (Entity entity in ecollection.Entities)
            {
                DataRow dr = dt.NewRow();
                dr["Name"] = entity.Attributes["name"].ToString();
                dr["accountid"] = entity.Attributes["accountid"].ToString();
                dt.Rows.Add(dr);
            }
       
            gridViewAccountName.DataSource = dt;
            gridViewAccountName.DataBind();
        }


        public IOrganizationService GetCRMService()
        {
            string orgUrl = "https://XXXX.api.crm5.dynamics.com/XRMServices/2011/Organization.svc";
            Uri OrganizationUri = new Uri(orgUrl);
            IOrganizationService service;
            ClientCredentials credentials = new ClientCredentials();

            credentials.UserName.UserName = "XXX@XXXXXXXX.onmicrosoft.com";
            credentials.UserName.Password = "XXXXXXXXX";
            try
            {
                using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, credentials, null))
                {
                    serviceProxy.EnableProxyTypes();
                    service = (IOrganizationService)serviceProxy;
                                   }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return service;
        }

The result is like below:

nameaccountid
vdvzsdfae87e930-d691-e511-80fa-3863bb345bf8
Fourth Coffee (sample)1af02229-5582-e511-80fe-3863bb347758
Litware, Inc. (sample)1cf02229-5582-e511-80fe-3863bb347758
Adventure Works (sample)1ef02229-5582-e511-80fe-3863bb347758
Fabrikam, Inc. (sample)20f02229-5582-e511-80fe-3863bb347758
Blue Yonder Airlines (sample)22f02229-5582-e511-80fe-3863bb347758
City Power & Light (sample)24f02229-5582-e511-80fe-3863bb347758
Contoso Pharmaceuticals (sample)26f02229-5582-e511-80fe-3863bb347758
Alpine Ski House (sample)28f02229-5582-e511-80fe-3863bb347758
A. Datum Corporation (sample)2af02229-5582-e511-80fe-3863bb347758
Coho Winery (sample)2cf02229-5582-e511-80fe-3863bb347758
Adventure test cycle7668e02f-238d-e511-80f4-3863bb36ef98


Tuesday, 1 December 2015

Workflow Vs JavaScript Vs Plugin comparison MS Dynamics CRM

WorkflowJavaScriptPlugin
SynchronousAsynchronousSynchronousEither
Can Get External DataNoYesYes
MaintenanceBusiness UsersProgrammersProgrammers
Can Run AsUserUserCRM System
On DemandYesNoNo
Nested Child ProcessYesNoYes
Executed After SavingAfterBeforeAfter
TriggersCreate, Field Change, Status Change, Assign to Owner, On DemandField change or Form LoadCreate, Field Change, Status Change, Assign to Owner, Delete

What are different stages used in Plug-In registration?

EventStage nameStage numberDescription
Pre-Event
Pre-validation
10
Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage may execute outside the database transaction.
securitySecurity Note
The pre-validation stage occurs prior to security checks being performed to verify the calling or logged on user has the correct permissions to perform the intended operation.
Pre-Event
Pre-operation
20
Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage are executed within the database transaction.
Platform Core Operation
MainOperation
30
In-transaction main operation of the system, such as create, update, delete, and so on. No custom plug-ins can be registered in this stage. For internal use only.
Post-Event
Post-operation
40
Stage in the pipeline for plug-ins which are to execute after the main operation. Plug-ins registered in this stage are executed within the database transaction.

Difference between CRM Discovery Service and CRM Metadata service?

CRM Discovery Service:

A single Microsoft Dynamics CRM installation can host multiple organizations on multiple servers therefore it is important to specify which organizations need to be accessed. The Discovery Web service returns a list of the organization the specified user belongs to and the URL endpoint address for each organization. It will only give organization related information.

CRM Metadata service

It is specific to CRM records. Use to interact with entities and attributes like create, update or delete, retrieve or add value to pick list. It holds information about entities and attributes.

  • An index in a book is Metadata, it helps you categorise/segment the information
  • Metadata is the characteristics of the data e.g. data type, length, description
  • It can show the relationships between data
  • Metadata allows efficiently classify and a structured way to organise data for ease of use
Use the IOrganizationService web service to read and write data or metadata.

One of the common uses for Metadata is to retrieve the string value of an optionset.  OptionSets are stored in the CRM database as Int numbers and the string values are in the Metadata.