All Posts

Dynamics 365 v9.0 onwards JavaScript scripting is not only limited to Forms, you can even customize views. More specifically you can just add icon in cells as of now, I was expecting more features actually but it didn’t have.

What is Offered?


As you can see in above image, those icons in view cells were already available in some OOB views, now you can use in custom view as well.

Where to customize?

2_View_Properties.png Goto any view’s property, you can see 2 new fields Web Resource and Function Name, which is very similar to Forms when you write JS.

What to write in Web Resource?

You need to write a JS function with 2 parameters, when you’ll add it to view, first parameters will receive rowData(value with metadata shown below for one cell) and userLCID(i.e. language code for current user). Based on those 2 inputs you can decide what icon to show. And name of this function goes in Function Name: field in View’s property.

/// rowData for just one cell
   "title":"Average order shipment time",
   "title_Value":"Average order shipment time",
   "ownerid":"Christa Geller (Sample Data)",
         "Name":"Christa Geller (Sample Data)",
   "createdon":"1/21/2017 4:20 AM",

Let’s Implement

I’ll be doing all the customizations in All Cases view of Case entity. So you can try it right away in new trial instance without creating any custom entity/view.

Add one JS web resource

Add one JS web resource

And write below code in it

function casePriorityIcons(rowData, userLCID) {
  var data = JSON.parse(rowData);
  var priority = data.prioritycode;
  var imgWebResource = "";
  var imgTooltip = "";
  switch (priority) {
    case "High":
      imgWebResource = "ashv_high";
      imgTooltip = "High Priority Case";
    case "Low":
      imgWebResource = "ashv_low";
      imgTooltip = "Low Priority Case";
      imgWebResource = "ashv_normal";
      imgTooltip = "Normal Priority Case";
  return [imgWebResource, imgTooltip];


In above code I’m reading cell data which is priority field of case, and according to value it will show color icon in from of it. I have added three 16x16(if you’ll take different size it will be scaled back to 16x16, so better take optimized size) icons with color Red, Yellow & Green for High, Normal & Low priorities respectively. Function returns an array of size 2, first element tells name of image web resource to show and second is tool-tip text. You can use below images in your web resource.

High : High Red Normal : Normal Yellow Low : Low Green

I’ve set Web resource and function name in All Cases view property for Priority field.


Publish everything and navigate to All Cases view.

Final Output Working!

Hooray! It’s working! I didn’t play anything with second parameter i.e. LCID, you can explore usecases and try.

Looks Good, but what happen behind the scenes

All this magic happens in layoutxml of view you can see below.

<?xml version="1.0" encoding="UTF-8"?>
<grid name="resultset" object="112" jump="title" select="1" icon="1" preview="1">
   <row name="result" id="incidentid">
      <cell name="title" width="300" />
      <cell name="ticketnumber" width="125" imageproviderfunctionname="" imageproviderwebresource="$webresource:" />
      <cell name="prioritycode" width="150" imageproviderfunctionname="casePriorityIcons" imageproviderwebresource="$webresource:ashv_ViewCustomizations" />
      <cell name="caseorigincode" width="100" />
      <cell name="customerid" width="150" />
      <cell name="ownerid" width="150" />
      <cell name="statecode" width="150" />
      <cell name="createdon" width="150" />

Here <cell name="prioritycode" width="150" imageproviderfunctionname="casePriorityIcons" imageproviderwebresource="$webresource:ashv_ViewCustomizations" /> got 2 extra attributes with name of web resource and function, they set image source and title while rendering view(see image below). 7_in_html.png

You can download this as unmanaged solution here.

Feel free to get in touch for any query regarding this.


All Posts

Buy Me A Coffee
©Ashish Vishwakarma. | Read More Posts