Advertisements

Archive

Archive for January, 2018

Dynamics Portals – Execute FetchXML and Parse the results – Liquid script

January 22, 2018 Leave a comment

In one of our Portal requirements, we had to build custom screen (i.e., Web Template) and retrieve the results from Dynamics 365 and bind to grid.

In this article, I am going to detail the steps to Execute FetchXML based on conditions and read the results.

As we know that Dynamics portals use Liquid to add dynamic content to pages, lets prepare the Liquid.

High level design:

  • Liquid executes only on the page load, hence create a new Web Template (will be called only in background) and add the Liquid in it.
    • Imp Points:
      • In the web Template where you copy your Liquid to, specify the ‘MIME Type’ as ‘application/json’WT_Resolved Cases
        • You need to uncheck, below property in the ‘Page Template’ associated with the Liquid ‘Web Template’.

WT_1

  • From my Search screen web template, on change of Dropdown, I will call the above Web Template by passing selected the view as Query string.
  • Up on calling the background template, it executes the Liquid and return the results in Json collection
  • Capture the collection and render the results in table.

Liquid to fetch Cases:

In below liquid, I am reading the query string parameter ‘V‘.

  • If ‘V’=0, Prepare ‘Open Case’ filter
  • If ‘V’=1, Prepare ‘Resolved Case’ filter
{% fetchxml cases %}
<fetch>
<entity name=”incident”>
<attribute name=”incidentid”/> <attribute name=”title”/> <attribute name=”createdon”/> <attribute name=”casetypecode”/> <attribute name=”ticketnumber”/> <attribute name=”subjectid”/> <attribute name=”caseorigincode”/> <attribute name=”customerid”/> <attribute name=”statuscode”/> <attribute name=”statecode”/> <order descending=”true” attribute=”createdon”/>
<filter type=”and”>
{% if request.params[‘V‘] == 0 %}
<condition attribute=”statecode” value=”0″ operator=”eq”/>
{% endif %}
{% if request.params[‘V’] == 1 %}
<condition attribute=”statecode” value=”1″ operator=”eq”/>
{% endif %}
</filter>
</entity>
</fetch>
{% endfetchxml %}
{ “totalcount”: {{ cases.results.total_record_count }},
“morerecords”: {{ cases.results.more_records }},
“page”: {{ request.params[‘page’] | default: 0 }},
“results”:
[
{% for item in cases.results.entities %} {
“incidentid”: “{{ item.incidentid }}”,
“title”: “{{ item.title }}”,
“statuscode”:”{{ item.statuscode.label }}”,
“createdon”:”{{ item.createdon }}”,
“subjectid”:”{{ item.subjectid.name }}”,
“customerid”:”{{ item.customerid.name }}”
}{% unless forloop.last %},{% endunless %} {% endfor %}
] }

Liquid’s Field Parsing Syntax:

If you notice, I have used {% for item in cases.results.entities %} to loop through the FetchXML results.

  • To read a Look up field text, {{ item.customerid.name }}
  • To read a Option set Label, {{ item.statuscode.label }}

🙂

Advertisements

Data Tables – Error – Non table node initialization

In one of my Dynamics portal’s requirements, I had to use Data Tables table control to bind the search results.

After referring helper files and configured the ‘Data Tables’ table control in my HTML, I encountered below error during the run:

Data Table - Error

Reason & Fix:

  • ‘Data Table’ table control requires a <table> place holder in the HTML page, which will get rendered with result set (i.e., json collection) in run time.

In your <script>:

var table = $(‘#customGrid‘).DataTable({
data: rows,
destroy: true,
columns: columns});

  • If you refer any control (i.e., Div/Span etc…) other than <table> you will get the error.

In your HTML <body>:

<table id=”customGrid” class=”display”></table>

  • I wrongly used <Div> control in my case and replaced with <Table> to fix the issue.

🙂

Categories: Misc Tags: ,

Dynamics Portals – SaaS – Refer helper files in Web Templates

In my portal, I got a requirement to build a ‘Search Screen’, which pulls the data from CRM and render the results.

To achieve this, I configured a ‘Web Template’ with ‘Search Screen’ using HTML and decided to use Data Tables  table control to bind the results.

The challenge is, to use ‘Data Table’ control, I must refer the helper files (i.e., datatable.min.js, jquery.datatable.css) in my ‘Search Screen’ Web Template.

One way to solve is to copy the content from the helper files (i.e., datatable.min.js, jquery.datatable.css) and paste within the Web Template. This is a crude way as the single Web Template size enormously grows and would become unmanageable.

Optimal way:

  • Create a separate Web Templates for Helper files (i.e., datatable.min.js, jquery.datatable.css)
  • Make sure you wrap the script file’s content in <script> tag, while pasting to Web Template.

WT - JS

  • Make sure you wrap the style sheet (i.e., css) files content in <style> tag, while pasting to Web Template.

WT - CSS

  • Refer the helper file Web Templates in the ‘Search Screen’ Web Template.
    • Syntax is {% include ‘Your helper file Web Template Name‘ %} 

Refer files 3

Notes:

  • Using Web  Files is one approach but you cannot attach JScript file to your Web File as the .js file extension is restricted.

🙂

Dynamics 365 – Plug-in registration tool – Unable to connect to organization

Other day, I could not connect to my 30 days trail Dynamics 365 organization (V 9.0) using Plug-in registration tool, which was working fine until a day before.

Issue was weird as the moment I select my organization after login, I was redirecting back to Plug-in ‘Login’ page with no exception details.

You may also get below exception, if your plug-in registration tool shows exception and when you download the Error log.

Error - 1

Reason and Fix:

  • Issue was with old version of Plug-in registration tool. You must have 9.0.0.7 version.
  • Download the PluginRegistrationTool v9.0.0.7 from nuget by following below steps
    • Open Visual Studio
    • Go to Tools -> NuGet Package Manager -> Manage NuGet packages for Solution
    • Browse and install “Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool” 9.0.0.7 version

NuGet package

  • After installation, go to your VS project physical folder and open “Packages” folder
  • You should get a “Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.9.0.0.7” folder under “Packages”
  • Open the “Plugin Registration tool.exe” and try connecting to your Organization.

NuGet package - Folder

Note:

  • There are other ways to install the “Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool” package from NuGet. Just for the sake of simplicity I used Visual studio approach to download the package.
  • If you are facing issues while establishing connection to CRM Organization service from your Console/Web Applications refer this blog for fix.

🙂