Dynamics CRM Common Workflow Activities Library

Hi ,

You can now download the Common Workflow Activities Library and save time by not implementing components repeatedly in each project such as

  • Apply Routing Rules
  • Share Record With Team
  • Check If User is in Role
  • Check If User is in Team

Download Link : https://msdyncrmworkflowtools.codeplex.com/

Dynamcis CRM Execute Sync Workflows In Order

Scenario & Problem:

I was performing an upgrade to CRM 2016 and one of the customer requirement was to convert all plugins to run time

workflows,multiple plugins were registered for the same event on the same entity by benefiting from execution order feature in

plugin which doesn't exist in run time workflows.

 

Solution:

let's say you have 2 WFs,

  • configure the second to be called on demand

  • call it from the first after finalizing all the logic

Connect To Dynamcis 365 Online using Power Shell

Hi,

In this post I am going to show a basic example using CRM SDK through power shell to connect to CRM .

Power shell is so useful when you need to execute operations through SDK without Visual studio installed in your environment.

Code :

clear;

#navigate to SDK Folder
cd C:\CRMSDK\SDK\Bin

#execute script
.\RegisterXRMTooling.ps1

#add crm snappin
Add-PSSnapin Microsoft.Xrm.Tooling.Connector

#Get Tool Alias
Set-Alias installUtil $env:windir\Microsoft.NET\Framework64\v4.0.30319\installutil.exe

#copy to gac
installUtil /u Microsoft.Xrm.Sdk.dll;

#Initialize connection
$CRMConn =Get-CrmConnection –ConnectionString "Url=https://MOQCRM20.crm6.dynamics.com/; Username=###; Password=###; authtype=Office365"

#Get Organization service proxy
$orgService=$CRMConn.OrganizationServiceProxy ;

#construct query
$query="<fetch mapping='logical' distinct='false' aggregate='true'>
<entity name='account'>
<attribute name='account' alias='recordcount' aggregate='count'/>
</entity>
</fetch>";

#Create Query expression

$queryExp = New-Object -TypeName Microsoft.Xrm.Sdk.Query.FetchExpression -ArgumentList $query ;

#Get Results
$results=$orgService.RetrieveMultiple($queryExp);

#Extract Count
$countItem=[Microsoft.Xrm.Sdk.AliasedValue]$results.Entities[0]["recordcount"]

Write-Host $countItem.Value

Dynamcis 365 - Override Lookup view using Java script

Hi,

I have encountered some scenarios  in which I needed to override lookup view columns or apply some filters on the results depending on dynamics conditions at run time on CRM form.

In order to do that , add the following piece of code in the on load event

The following example filters results set no a specific case type

 

var viewId = "{00000000-0000-0000-0000-000000000001}";

//add the entity name
var entityName = "incident";

// add the view display name
var viewDisplayName = "Problem Cases";

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='incident'>" +
" <attribute name='title' />" +
"<attribute name='customerid' />" +
"<attribute name='incidentid' />" +
"<order attribute='title' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='bps_type' operator='eq' value='200000005' />" +
" </filter>" +
" </entity>" +
"</fetch>";

var layoutXml = "<grid name='resultset' object='1' jump='productid' select='1' icon='1' preview='1'>" +
"<row name='result' id='incidentid'>" +
"<cell name='title' width='150' />" +
"<cell name='customerid' width='150' />" +
"</row>" +
"</grid>";

Xrm.Page.getControl("parentcaseid").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

Connect to Dynamics 365 using C# SDK

Hi,

I am going to show  in a few steps how to create an organization service proxy for dynamics 365 .

Steps :

  • Create a new project in visual studio
  • Add nuget package :"Microsoft.CrmSdk.CoreAssemblies"
  • Add the following piece of code

CrmServiceClient conn = new CrmServiceClient("Url=https://moqcrm20.crm6.dynamics.com/; Username=test; Password=test; authtype=Office365");

// Cast the proxy client to the IOrganizationService interface.
var _orgService = (Microsoft.Xrm.Sdk.IOrganizationService)conn.OrganizationWebProxyClient != null ? (Microsoft.Xrm.Sdk.IOrganizationService)conn.OrganizationWebProxyClient : (Microsoft.Xrm.Sdk.IOrganizationService)conn.OrganizationServiceProxy;

How To : Obtain Records Count Without Retrieving Rows of Data in CRM Using C# SDK

Brief:

Let's suppose we have a scenario that requires to get only records count of the entity "Account".

Code:

string fetchQuery = @"<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='entity name'>
<attribute name='attribute name' aggregate='count' alias='aliasName'/>
</entity>
</fetch>";

EntityCollection value = _serviceProxy.Execute(new FetchExpression(fetchQuery));

              Returned result will be something as follow:

<resultset morerecords="0"'>
<result>
<aliasName>20</aliasName>
</result>
</resultset>

Note: you can check how to create  Service Proxy at the following link

Quick View Form and sub grid Issue in Dynamics 365

Hi,

Intro :

I encountered a problem while working with quick view forms having sub grids.

The quick view form is meant to display the account details upon selecting an account on lookup in custom entity form.

Problem:

Quick view form has sub grid displaying related record to account such as cases and opportunities , the problem occurs whenever you change the select account , all the details are updated to reflect the new selected account except the sub grids .

 They keep displaying the related records to the old one.

Fix :

  1. Add on change event handler on the account lookup
  2. Include the following piece of code in your java script function

var quickViewControl = Xrm.Page.ui.quickForms.get("your quick view form name");
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {
quickViewControl.refresh();
}
}

Export Translations in Dynamics CRM Progrmatillcally

SDKThe following code illustrates how to export Translation file from CRM problematically:

ExportTranslationRequest req = new ExportTranslationRequest();
req.SolutionName = "Final Solution";
ExportTranslationResponse resp = (ExportTranslationResponse)service.Execute(req);
String outputDir = @"C:\CRMTranslaions\";
byte[] exportXml = resp.ExportTranslationFile;
string filename = "CRMTranslations" + ".zip";
File.WriteAllBytes(outputDir + filename, exportXml);
Console.WriteLine("Translations exported to {0}.", outputDir + filename);