Showing posts with label CRM 2011/2013/2015/2016/Dynamics 365. Show all posts
Showing posts with label CRM 2011/2013/2015/2016/Dynamics 365. Show all posts

Monday, 27 April 2020

Check the status on Solution Import - Dynamics 365 Customer Engagement

Hi Everyone,

Certainly, everyone Dynamics 365 CE Consultant/Architect must have started importing the solutions and went for dinner, lunch, break or checked the mobile thinking the solution import would take some time. After they come back, the import might be still going on and at that time everyone would be eager to check what exactly the status of the import.

Also sometimes, knowingly or unknowingly you might cancelled/closed import wizard thinking let's start the import again and when you try again the system must have shown a message saying "The import is in progress." and you never know when it completes.

We have a solution for this, we can check the progress of the solution from Import Jobs. Open Advance Find and look for import Jobs, add a filter to show the records created on from last one or two hours (I normally apply the filter on Created on, if you want to get the results and sort on CreatedOn column). You will see the results showing percentage.


Hope this helps.

--
Happy 365'ing
Gopinath

Tuesday, 4 February 2020

Cannot update Closed or Cancelled Activity - Not for Admin

Hi Team,

Today have observed a strange behavior when updating the completed activity. We have written the code to update the Completed Activity in the plugin and as we always do use Admin account for our development. Everything was working at the time of development and Testing team complained that it was not working. When we have checked in detail, we found that only Admins are able to update completed activity records. We have changed our code to use Admin User Account for updating the Activity inside the plugin and it started working like a champ.

Hope this helps.

--
Happy 365'ing
Gopinath

Tuesday, 7 January 2020

Dynamics 365 CE - Optimistic Concurrency - Handling Concurrent Transactions

Hi Everyone,

Let's discuss something on Optimistic Concurrency today. 

What are Concurrent Transaction?

When two or more users need to update a same record at the same time, the changes made by the last user will be saved and this results data loss. The operations performing by users on the record at the same are known as Concurrent Transactions.

In general, there are two ways to control this behavior.

1) Pessimistic Concurrency Control
When a user is modifying the data, another user can’t access the same data at same time as the access has been locked on that data.
2) Optimistic Concurrency Control
This feature provides the ability for your applications to detect whether an entity record has changed on the server in the time between when your application retrieved the record and when it tries to update or delete that record.

On all entities, you will see a OOB filed "Version Number" of type Timestamp and it gets updated by the system every time when the record updates.

In the below code, I am retrieving the record and trying to update but before updating the record using the code I am going update the record manually in CRM. The below code will throw the exception as below.

"The version of the existing record doesn't match the RowVersion property provided."

            try
            {
                // Retrieving the account record.
                Entity entAccount = crmService.Retrieve("account", new Guid("4921991e-162d-ea11-a813-000d3a59f4b3"), new ColumnSet(new string[] { "name" }));
                // Creating a new object and updating the account record that was retrieved above by setting Concurrency Behavior to If RowVersionMatches.
                Entity entAccountToUpdate = new Entity("account");
                entAccountToUpdate.Id = entAccount.Id;
                entAccountToUpdate["name"] = "My Account Name";
                // Setting up the Row Version.
                entAccountToUpdate.RowVersion = entAccount.RowVersion;
                UpdateRequest accountReq = new UpdateRequest()
                {
                    Target = entAccountToUpdate,
                    ConcurrencyBehavior = ConcurrencyBehavior.IfRowVersionMatches
                };
                UpdateResponse accountUpdateResponse = (UpdateResponse)crmService.Execute(accountReq);
            }
            catch (FaultException<OrganizationServiceFault> fx)
            {
                switch (fx.Detail.ErrorCode)
                {
                    case -2147088254: // ConcurrencyVersionMismatch
                    case -2147088253: // OptimisticConcurrencyNotEnabled
                        throw new InvalidOperationException(fx.Detail.Message);
                    case -2147088243: // ConcurrencyVersionNotProvided
                        throw new ArgumentNullException(fx.Detail.Message);
                    default:
                        throw fx;
                }
            }

Hope this helps.

--
Happy 365'ing
Gopinath

Sunday, 15 December 2019

Dynamics 365 Customer Engagement Diagnostics Tool for Online - Check Latency

Hi Everyone,

Sometimes the performance of the system would be very bad and the customers might complain that was working fine last day. We all know that Performance is the big thing and have to consider multiple parameters. However, sometimes it is worth to check the Latency of the system from multiple places and multiple networks to understand.

Here are the steps for the same.

1) Login to the system which you would like to check.
2) Copy the URL till .com and append with /tools/diagnostics/diag.aspx and hit the browser.
https://abc.crm.dynamics.com/tools/diagnostics/diag.aspx
3) Below Page would open up and click on Run to start the diagnostics.
Hope this helps.

--
Happy 365'ing
Gopinath

Friday, 6 December 2019

Get/Set Lookup field value using JavaScript in Dynamics CRM/Dynamics 365 CE

Hi Everyone,

Sometimes, it is really good to keep required and repeated code handy. 

Here is the JavaScript code for getting and setting value from CRM/CE Lookupfield.

// Get the Lookup Value.
function getLookupDetails(executionContext) {
    var formContext = executionContext.getFormContext();
    var entityName, entityId, entityLabel, lookupFieldObject;
    lookupFieldObject = formContext.data.entity.attributes.get("parentcontactid");
    if (lookupFieldObject.getValue() != null) {
        entityId = lookupFieldObject.getValue()[0].id.slice(1, -1);
        entityName = lookupFieldObject.getValue()[0].entityType;
        entityLabel = lookupFieldObject.getValue()[0].name;
    }
}

// Set the Lookup Value.
function setLookupField(executionContext) {
    var formContext = executionContext.getFormContext();
    var lookupData = new Array();
    var lookupItem = new Object();
    lookupItem.id = "74a968c5-6505-ea11-a81e-000d3a300ec6";
    lookupItem.name = "Nancy";
    lookupItem.entityType = "contact";
    lookupData[0] = lookupItem;
    formContext.data.entity.attributes.get("parentcontactid").setValue(lookupData);

}

Hope this helps.

--
Happy 365'ing
Gopinath

Monday, 25 November 2019

Get GridContext form the button on the Subgrid - SelectedControl

Hi Everyone,

Today I was working on adding a button on the some sub grid and on click I have to refresh that Grid after doing some business operation.  To refresh the grid, we have to get the Grid Context. This can be easily achieved by passing SelectedControl as a CRM Parameter.

function onSubgridButtonClick(selectedControl) {
    if (selectedControl.name == "ABC") {
        // Your logic
    }

}

Primary Control - Gets the FormContext
Selected Control - Gets the GridContext

Hope this helps.

--
Happy CRM'ing
Gopinath

Saturday, 16 November 2019

Associate and Disassociate Records using C# Code - Dynamics CRM/365

Hi Everyone,

This might be a old one but somehow I could not get this piece code very easily.

Here is the piece of C# code for Associating and Dissociating two records with N:N relationship.

Associate
string relationshipName = "<<RelationShipName>>";
Relationship relationship = new Relationship(relationshipName);
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
EntityReference secondaryEntity = new EntityReference("SecondEntitySchemaName", GUIDOfSecondEntityRecord);
relatedEntities.Add(secondaryEntity);
crmService.Associate("FirstEntitySchemaName", GUIDOfFirstEntityRecord, relationship, relatedEntities);

Disassociate
string relationshipName = "<<RelationShipName>>";
Relationship relationship = new Relationship(relationshipName);
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
EntityReference secondaryEntity = new EntityReference("SecondEntitySchemaName", GUIDOfSecondEntityRecord);
relatedEntities.Add(secondaryEntity);
crmService. Disassociate ("FirstEntitySchemaName", GUIDOfFirstEntityRecord, relationship, relatedEntities);


Hope this helps.
--
Happy 365'ing

Gopinath

Monday, 11 November 2019

Show button only when the record is selected - Selection Count Rule

Hi Everyone,

Today I was working on adding some button on the Subgrid and the requirement was to show the button when at least single record is selected.

We can easily achieve this using a Enable Rule - Selection Count Rule. Here is the enable rule of the same, we just have to attach this rule to the button command.


      <EnableRule Id="...SelectionCount.EnableRule">
        <SelectionCountRule AppliesTo="PrimaryEntity" Minimum="1" Default="false" />
      </EnableRule>

Hope this helps.

--
Happy 365'ing
Gopinath

Sunday, 16 December 2018

Power of Pre-Validation Stage in Dynamics 365

Hi,

Today, I got an interesting requirement on the Account Deletion. we all know that when we delete a account, all the records that are associated with it will delete as it is defined in Relation Behaivour. "Delete - Cascade all" and we cannot even change the configuration. 



After some search we got to know the power of Pre-Validation step. we have written a plugin and registered on the PreValidation step. Written a logic to loop through the contacts that are associated with the deleting account and updated ParentAccount lookup of the contacts with null. 

Hope this helps.

--
Happy CRM'ing
Gopinath

Monday, 3 September 2018

The 'ascending' attribute is not declared - Importing Solution

Hi,

Today I have received the below error while importing the solution in CRM. I was not able to get anything by seeing the error as the information given was not helping to find the exact error and fix it. 



After some search able to find the fix. 

1) Extract the Solution zip file.
2) Open Customizations.xml in a XML Editor (I normally use Visual Studio)
3) Search for "ascending" and remove this text "ascending="true" whereever you find it.
4) Zip the components and import again. You will not get any error this time.

Hope this helps.

--
Happy CRM'ing
Gopinath

Tuesday, 27 February 2018

Resolve and Cancel Cases in CRM/Dynamics 365 CE using C#

Hi,

I was working on Service Module and had to develop a tool which can Resolve and Cancel cases.

Here is the C# code for the same.

To Resolve the Cases
        Entity IncidentResolution = new Entity("incidentresolution");
        IncidentResolution.Attributes["subject"] = "Subject Closed";
        IncidentResolution.Attributes["incidentid"] = new EntityReference("incident", guidCase);
        // Create the request to close the incident, and set its resolution to the
        // resolution created above
        CloseIncidentRequest closeRequest = new CloseIncidentRequest();
        closeRequest.IncidentResolution = IncidentResolution;
        // Set the requested new status for the closed Incident
        closeRequest.Status = new OptionSetValue(5);
        // Execute the close request
        CloseIncidentResponse closeResponse = (CloseIncidentResponse)iService.Execute(closeRequest);

To Cancel the Cases
       SetStateRequest request = new SetStateRequest();
       request.EntityMoniker = new EntityReference("incident", new Guid(strGuids[intGuid]));
       request.State = new OptionSetValue(2);
       request.Status = new OptionSetValue(6);
       SetStateResponse objResponse = (SetStateResponse)iService.Execute(request);

Hope this helps.

--
Happy CRM'ing
Gopinath

Saturday, 9 September 2017

Send Email to unresolved Recipients

Hi,

I was working some email functionality today and question came up saying can we send email to external people which are not part of Lead, Contact, Account or any CRM object.

An immediate answer from my mouth is No but some how my mind stopped and did a quick check and came to know that there is an option for that.

Settings -> Administration -> System Settings -> Email Tab - Allow messages with unresolved email recipients to be sent To Yes


Hope this helps.

--
Happy CRM'ing
Gopinath

Wednesday, 16 August 2017

'Cannot specify child attributes in the columnset for Retrieve' when Merging two Accounts in CRM

Hi,

Today, I was writing C# code for merging two accounts in CRM. For sometime, it was working fine and suddenly it started giving the below error.

Not sure, what happened. Just went back and checked the differences between then and now and understood that I have added couple of fields to the UpdateContent entity object and those are causing the issue.

After some search came to know it was happening because of lookup fields. Whenever, we added lookups field we have to make sure that the entityreference object should not contain value for Name property and we have to explicitly add name attribute to the UpdateContent object as below.

// Add EntityLogicalName + 'Name' property to UpdateContent object.
// updateContent.Attributes.Add("transactioncurrencyame", erfTransactionCurrencyId.Name);
updateContent.Attributes.Add(erfTransactionCurrencyMain.LogicalName + "name", erfTransactionCurrencyId.Name);
// Set the Name Property of the Look up object (Entity Reference) to Null.
erfTransactionCurrencyMain.Name = null;
// Add Lookup object (Entity Reference after setting Name value to Null) to the UpdateContent Object.
updateContent.Attributes.Add("transactioncurrencyid", erfTransactionCurrencyMain);


Hope this helps.

--
Happy CRM'ing
Gopinath