Web API and plural names

beware

JavaScript Plural name issue almost killed us, following post saved us. ūüôā …. CRM 2016 Web API and plural names … Thanks for the post nice post. I’m re-posting the article ..

The new Web API available for CRM 2016 is based on OData V4 protocol and the endpoint is /api/data/v8.0/

Continue reading “Web API and plural names”

DLL merge and MSD CRM/365 (on-prem/On-Line)

Tips & Trics

While working as a developer, many times we will have some readymade tools or class libraries / DLLs, which were developed by some other developers and they publish for developer kind. Salute to their generosity.

We use those libraries in our development and our life becomes little easier. But while deploying it on other environments we have to install those things and or keep those DLLs on another environment, if we miss it then because of those open libraries, development breaks.

 

So in such conditions, we can merge multiple DLLs in one to make our life bit easier.

If it’s exe, user following function to make one DDL.

Advantage: it will keep the original identity of the DDL.

Disadvantage: it won’t work for the library building. For e.g. CRM plugins

Here is that great function …

private static void AsseblyResolveEvent()
 {
 AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
 {
 String resourceName = "AssemblyLoadingAndReflection." +
 new AssemblyName(args.Name).Name + ".dll";
 using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
 {
 Byte[] assemblyData = new Byte[stream.Length];
 stream.Read(assemblyData, 0, assemblyData.Length);
 return Assembly.Load(assemblyData);
 }
 };
 }

Curtsy: This function has written by Jeffrey Richter, here is his article for it.

If it’s DDL and or class libraries, ILMerge will useful.

Advantages: it’s free and lite installation. Easy to use.

Disadvantage: After merging DDLs with ILMerge, DDL will lose its identity, that’s why we can not use for CRM plugin libraries. While writing commands we need to bit careful else spelling mistake might frustrate you. ūüėČ

You need to install it after download from here. Then by following commands, you can merge multiple DDLs together.

Steps: Once its installed, open command window with admin rights and execute it, follow the commands

Step 1: Download ILMerge utility and install it in your machine
http://www.microsoft.com/en-us/download/details.aspx?id=17630

Step 2: Compile and Publish your Project to a folder (eg: C:\Publish\)

Step 3: Use the ilmerge command to merge the exe and dll files and output single exe file

ILMerge Command

Syntax (Simple*): ilmerge <input assembly 1> <input assembly 2> /out:<output file> /target:<dll|exe|winexe>

*For the complete set of options and syntax refer ILMerge Documentation

Example:

C:\Program Files\Microsoft\ILMerge>ilmerge C:\Publish\MyProgram.exe C:\Publish\MyLibrary.dll /out:C:\Publish\MyWinApp.exe /target:winexe /ndebug

ilmerge¬†‚Äď Command

MyProgram.exe¬†‚Äď Output from the published folder

MyLibrary.dll¬†‚Äď Any library used in the program

/target:winexe¬†‚Äď We need to output a single exe file for Windows Platform

/output¬†‚Äď Output folder and filename

/ndebug¬†‚Äď To disable debug (.pdb file)

Curtsy: Arun Ramchandran’s blog¬†, for more info, explore this link¬†and this link.

Above both options won’t be useful for MSD CRM or MSD 365. ūüėĒ

So, to make those libraries useful for these environments we have to create a folder in your plugin project so it will be part of plugin project. And we don’t need to merge it anymore. ūüėČ

Thus, we have two options available for it,

If those libraries are open source then we will get everything available online(thanks to generous great developers), just get only those classes which useful for you and ignore the rest of classes from that DDL.

But if it’s not open source then we need bit more efforts. As we need to use ILSpy or some similar add-on to decompile that code and then use in our plugin or workflow library.

There is another way for same is merging these files together along with its signature. Here are the details for it. (Courtesy: github )

Use Nuget to add ILMerge.MSBuild.Task to your Visual Studio project:

Install-Package ILMerge.MSBuild.Task

Also, install the ILMerge Package:

Install-Package ilmerge

Build your project. The merged assembly will be stored in an ILMerge folder under the project output.

Merge Assemblies With Copy Local = True

By default, all references with Copy Local equals true are merged with your project output.

Creating a Static List of Assemblies to Merge

It is also possible to use a static list of assemblies instead of inspecting the Copy Local property. This can be done through a configuration file added to the root of your project. Create a JSON file and name it as follows:

ILMergeConfig.json

The following snippet uses the InputAssemblies property to specify the files to be merged into the project output.

{
	"General": {
		"InputAssemblies": [
		  "$(SolutionDir)libs\\XrmUtils.Plugins.Abstractions.dll", 
		  "$(SolutionDir)libs\\XrmUtils.Plugins.Utilitiesd.dll" 
		]
	}
}

You don’t have to specify a path if assemblies are expected to be in the target directory:

{
	"General": {
		"InputAssemblies": [
		  "XrmUtils.Plugins.Abstractions.dll", 
		  "XrmUtils.Plugins.Utilities.dll" 
		]
	}
}

See Configuration File complete reference.

That’s it for now.

Thanks!

Few more ref

  1. http://develop1.net/public/post/2018/10/21/ILMergeNotSupported
  2. https://medium.com/capgemini-dynamics-365-team/using-gov-uk-notify-in-a-dynamics-crm-plugin-without-ilmerge-cf89f372cd5d 

Continue reading “DLL merge and MSD CRM/365 (on-prem/On-Line)”

Refresh roll up field from plugin

data retrival

Roll up fields are very useful, it reduce lots of manual and coding efforts. This rolls up field will auto refresh by each hour by default, off course it can be changed any time.

But what if developer wants to refresh it on fly from plugin itself to make following logic to work perfectly, which is dependent on this roll up field? Is there any way for this? or roll up fields are not useful in such a condition.

Yes, there is way we need to execute “CalculateRollupFieldRequest and CalculateRollupFieldResponce” functions to refresh roll up attributes.

Call to refresh the roll up field, here is sample code….

Entity incident = new Entity(“incident”)
{ Id = incidentId };

int refreshedExAssetRequested = RefreshRollup(context, incident, “soft_exassetrequested”);
context.Trace(“new soft_exassetrequested: ” + refreshedExAssetRequested);

Function to execute

/// <summary>
/// refresh attribute
/// </summary>
/// <param name=”context”></param>
/// <param name=”entityToRefresh”></param>
/// <param name=”fieldToRefresh”></param>
/// <returns></returns>
internal static int RefreshRollup(SelectContext context, Entity entityToRefresh, string fieldToRefresh)
{

// print the old value of the roll-up field
context.Trace(“Total Accepted Qty (updated)= ” + entityToRefresh.GetAttributeValue<int>(fieldToRefresh));
// create a request by passing an entity reference and the targeted rollup field name
CalculateRollupFieldRequest crfrRequested = new CalculateRollupFieldRequest
{
Target = new EntityReference(entityToRefresh.LogicalName, entityToRefresh.Id),
FieldName = fieldToRefresh
};

CalculateRollupFieldResponse responseRequested = (CalculateRollupFieldResponse)context.OrgService.Execute(crfrRequested);

// read the entity and value of the rollup field
entityToRefresh = responseRequested.Entity;

// print the new value of the roll-up field
context.Trace(“Total Accepted Qty (updated)= ” + entityToRefresh.GetAttributeValue<int>(fieldToRefresh));

return entityToRefresh.GetAttributeValue<int>(fieldToRefresh);
}

Also, same rollup can be refreshed from JavaScript, here is sample code for it. Only thing you need to keep in the memory is that this refresh is async call and may take 10 second to refresh.

function RefreshSHRollup(entityToRefresh, entityId, rollupField) {

    //var requestUrl = Xrm.Page.context.getClientUrl() + "/api/data/v9.0/CalculateRollupField(Target=@tid,FieldName=@fn)?@tid={'@odata.id':'" + entityToRefresh + "(" + entityId + ")'}&@fn='" + rollupField + "'";
    var requestUrl = Xrm.Page.context.getClientUrl() + "/api/data/v9.0/CalculateRollupField(Target=@p1,FieldName=@p2)?@p1={'@odata.id':'" + entityToRefresh + "s(" + entityId + ")'}&@p2='" + rollupField + "'"

    try {

        var req = new XMLHttpRequest();
        req.open("GET", requestUrl, false);
        req.send();

    } catch (e) {
        console.log(e.message);
    }   

}

That’s it!

Thanks.

Colourful MSD 365 Views/Grid

new things

Many times client ask to make views colourful based on some condition in MSD 365.

In earlier MSD CRM version, it was big and totally unsupported change. But now we can do the same thing in a supported way.

Here we need to create JavaScript library for this single function, as it won’t work if the same library has any other function (it’s strange, but happened with me). Well, here are the steps for it

  1. Create attribute or use existing option set, e.g. priority
    1. Option set text: Low, value: 15
    2. Option set text: Normal, value: 14
    3. Option set text: Critical, value: 12
    4. Option set text: Blocker, value: 11
    5. …and so on…
  2. Get colour images of 16X16 for each type e.g.
    1. Option set text: Low ==> Image: soft_Low
    2. Option set text: Normal ==> Image: soft_Normal
    3. Option set text: Critical ==> Image: soft_Critical
    4. Option set text: Blocker ==> Image: soft_Blocker
    5. …and so on…
    6. please no that its should be fine with all image type but i tried with PNG only 
  3. Create a JavaScript library in system keep below function
  4. Register this function on the view ==> Attribute (Priority). Here is the post for how to execute JavaScript on MSD 365 views.
  5. It will look like below …

colourful view

6. well, here is JavaScript function for your reference ….

//exe on incident view
function displayIconTooltip(rowData, userLCID) {

//alert(“..yes, its View Script..!!”);
var str = JSON.parse(rowData);
var col_data = str.soft_priority_Value; // this is the attribute name from system
var imgName = “”;
var tooltip = “{” + col_data + “}”;

switch (col_data) {
case 16: //it is optionset value
imgName = “img_VeryLow”;¬† // it’s image name from system
tooltip = “Very Low”;
break;
case 15:
imgName = “img_Low”;
tooltip = “Low”;
break;
case 14:
imgName = “img_Normal”;
tooltip = “Normal”;
break;
case 13:
imgName = “img_High”;
tooltip = “High”;
break;
case 12:
imgName = “img_Critical”;
tooltip = “Critical”;
break;

case 11:
imgName = “img_Blocker”;
tooltip = “Blocker”;
break;

default:
imgName = ” “;
tooltip = “N/A”;
break;

}
var resultarray = [imgName, tooltip];
return resultarray;

}

7. This same configuartion will work for MSD Gris as well..

color grid

Caution:

  1. Please note that this function will execute on each record one by one, so it may affect the performance.
  2. This configuration won’t work for Editable Grid.

Thanks!!

 

 

 

MB2-718 Certification: (Microsoft Dynamics 365 Customer Service) ‚Äď Case Management (Part One)

Awesome stuff !!

Microsoft Dynamics 365

As I revised for the MB2-718 exam (Microsoft Dynamics 365 Customer Service) I’m creating blog posts detailing all aspects of my revision. I hope these posts will aid anyone who is also revising for this exam. In this post I will provide details on case management.

The skills measured statement relating to case management is shown below. From this we can see that case management covers a wide variety of capabilities;


In total I will cover quite a bit of ground! In this post I will include;

  • Cases An Overview
  • Case Views
  • Searching Cases
  • Creating Cases from Activities
  • Case Business Process Flow

The in a second post I will cover;

  • Resolving Cases
  • Routing Cases
  • Parent / Child Cases
  • Merge Cases

As already mentioned cases are a fundamental part of the service functionality in Dynamics 365, therefore I suggest you spend a significant amount of you exam preparation time creating cases…

View original post 1,816 more words

Automated UI testing API for Dynamics 365

TestingAutomation

Overview

The purpose of this library is to provide Dynamics customers the ability to facilitate automated UI testing for their projects. These API’s provide an easy to use set of commands that make setting up UI testing quick and easy. The functionality provided covers the core CRM commands that end users would perform on a typical workday and working to extend that coverage to more functionality. Continue reading “Automated UI testing API for Dynamics 365”

Get complete trace through multiple level plugins

 

trace

While extending MSD CRM with complicated business¬†requirements, we write many plugins; one plugin triggers¬†from another plugin’s create or update. In such a scenarios if one of child plugin breaks then it will provide only current plugins trace, it’s very hard to analyse that particular¬†scenario¬†or replicate that same scenario in Dev environment without the proper trace. ¬†if we develop with normal¬†plugin sample it won’t generates¬†that all trace from¬†various different plugins, it will provide only one plugin’s trace where it actually¬†got a break.¬† Continue reading “Get complete trace through multiple level plugins”

Plugin debugging

solution-mgmt

Have you ever stuck in a situation where the plugin working perfectly in a test environment but not the SIT/UAT/Production environment?

Remote debugging might be a tricky setup in most of the production server because of the firewall constraint or even many times developer does not have access to the following environment. In such situation how we can survive, Debugging skills will save us in this situation.

Debugging is must skill for every developer while updating or fixing any code; we need debugging skills.¬† Continue reading “Plugin debugging”

Query hierarchical data

Retiring hierarchical data is easy, we don’t need to iterate by for/while loop. just use ‘Above’ or ‘Under’ keywords, then it will serve you all parents or all child available.

in regular query, just ‘ConditionOperator.Above’ to get all parents.

in regular query, just ‘ConditionOperator.Under’ to get all child.

How to create this type of structure

Continue reading “Query hierarchical data”