Sample code to hide out of the box reports using ReportVisibility class in Dynamics 365


Recently we wanted to hide OOB reports for our users.

One way of doing it is either change those report from Organization owned to personal

or change the Display in Area for those reports (this will hide those reports from all other views except the “All Reports, Including Sub Reports” view), as all other OOB Views for the reports uses the Reports Area filter. Another option of course is to update the filter criteria for those views or deactivate those views.

In our case, we simply updated the Display In property for all the OOB reports. Below is the sample code that we used. Basically, every report can have 0 or more (max 3) related Report Visibility records associated to it. (i.e. for forms, lists or reports area). In the below code we have looped through all the OOB reports and deleted all the associated ReportVisibility records for that report.

Hope it helps..

“Cannot delete an active workflow definition” error while importing solution in Dynamics 365


Recently while trying to import a solution (managed) to one of our test environments we got the below error.

import

The reason being one of the SLA(s) that was part of the solution was in Active stage in the test environment to which solution was getting imported.

Deactivating the SLA and then importing the solution again worked properly.

Hope it helps..

Configuration Migration Utility not migrating all the records in Dynamics 365


Recently while trying to move data for one of our entities, we saw that Configuration Migration Utility was only moving 7 records out of 11.

Even in the log, we couldn’t find any error message.

<<Drive>>:\Users\<<username>>\AppData\Roaming\Microsoft\Microsoft Dynamics® CRM Configuration Migration Utility

In fact, exporting and importing the records through excel was also only adding the 7 records.

The way we fixed this issue was by specifying the primary field of the entity as the fields to compare on update.

Running the import again this time imported all the records.

Hope it helps..

Form now showing up properly after solution import in Dynamics 365.


Recently after moving our solution from dev to test, we saw that one of our lead forms was not showing up properly.

As we can see below, the contact section is missing and the Social Pane instead of being in center is left aligned below the Summary tab label.

The fix for this was to enable the Bing Map from the System Settings in the Test.

The same record in our test, after enabling the Bing Map.

Hope it helps..

Sample Code to bulk update the record using ExecuteMultiple in Dynamics 365


Sharing a sample code that can be used ExecuteMultiple to bulk update the records.


private void MyForm_Load(object sender, EventArgs e)
{

var orgProxy = GetOrgProxy();

// place your fetch xml code to retrieve the records to be updated
var fetchXML = @"FetchXMLQuery";

var multipleRequest = new ExecuteMultipleRequest()
{
// Assign settings that define execution behavior: continue on error, return responses.
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = true,
ReturnResponses = true
},
// Create an empty organization request collection.
Requests = new OrganizationRequestCollection()
};

// get all the records > 5000
var totalRecords = GetTotalRecordsFetchXML(orgProxy, fetchXML);

// split the lst of entity to child list
// specify the size of the batch i.e. 500 here
var lstlstEntity = SplitList(totalRecords, 500);

// loop through each of the list and create the request and add it to Execute Multiple Request
foreach(var lstEntity in lstlstEntity)
{
multipleRequest.Requests.Clear();
foreach (var entity in lstEntity)
{
UpdateRequest createRequest = new UpdateRequest { Target = entity };
// add the field to be updated
entity.Attributes["sab_referencenumber"] = "1000";
multipleRequest.Requests.Add(createRequest);
}

ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)orgProxy.Execute(multipleRequest);
}
}

/// <summary>
/// Function to split the list into child list
/// </summary>
/// <param name="locations"></param>
/// <param name="nSize"></param>
/// <returns></returns>
public static List<List<Entity>> SplitList(List<Entity> locations, int nSize = 30)
{
var list = new List<List<Entity>>();
for (int i = 0; i < locations.Count; i += nSize)
{
list.Add(locations.GetRange(i, Math.Min(nSize, locations.Count - i)));
}
return list;
}

 

private static List<Entity> GetTotalRecordsFetchXML(OrganizationServiceProxy orgProxy, string fetchXML)
{
XDocument xDocument = XDocument.Parse(fetchXML);
var fetchXmlEntity = xDocument.Root.Element("entity").ToString();

EntityCollection entityColl = new EntityCollection();
List<Entity> lstEntity = new List<Entity>();
int page = 1;
do
{
entityColl = orgProxy.RetrieveMultiple(new FetchExpression(
string.Format("<fetch version='1.0' page='{1}' paging-cookie='{0}'>" + fetchXmlEntity + "</fetch>",
SecurityElement.Escape(entityColl.PagingCookie), page++)));

lstEntity.AddRange(entityColl.Entities);
}
while (entityColl.MoreRecords);

return lstEntity;
}

 

// Get service instance
public static OrganizationServiceProxy GetOrgProxy()
{
IServiceManagement<IOrganizationService> orgServiceManagement =
ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://orgname.crm4.dynamics.com/XRMServices/2011/Organization.svc"));

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials.UserName.UserName = "username";
authCredentials.ClientCredentials.UserName.Password = "password";
AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

return new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);

}

Hope it helps..

 

Solved – System.ArgumentNullException: Value cannot be null.Parameter name: SandboxAppDomainHelper.Execute: The plug-in type could not be found in the plug-in assembly in Dynamics 365


We got the below error while in one of our plugin assemblies. 

As it turned out we were referencing the latest, version 9 Dynamics 365 assemblies in our plugin project, against our Dynamics 365 Environment which was still in version 8.2.

Adding the appropriate NuGet Package (i.e. 8.2.0.0) fixed the issue for us.

The helpful post

http://blogs.it.ox.ac.uk/benwalker/2017/09/12/system-io-fileloadexception-error-in-plugin-deployed-by-crm-developer-toolkit-to-dynamics-2015/

Hope it helps..

Advertisements