Advertisements

Archive

Posts Tagged ‘Liquid Script’

Liquid script to fetch Contact names – Dynamics Portals SaaS

December 26, 2017 Leave a comment

In Dynamics portals (SaaS) to make CRM server calls to retrieve the data we must rely on Liquid Script.

In this article, I am going to retrieve Contacts and loop through to capture Contact ‘Full Name‘ using Liquid Script and display on a Web Template.

Liquid Script - 1

Liquid script to fetch Contacts:

{% fetchxml settings %}
<fetch version=”1.0″ output-format=”xml-platform” mapping=”logical” distinct=”false”>
<entity name=”contact”>
<attribute name=”fullname” />
<attribute name=”telephone1″ />
<order attribute=”fullname” descending=”false” />
</entity>
</fetch>
{% endfetchxml %}
{% assign result = settings.results.entities %}
{% for item in result %}
{% assign Names = {{item.fullname}} | append: ‘ , ‘ | append: {{Names}} %}
{% endfor %}

// Set the Concatenated text to Span so that it can be read in JScript

<span id=”spanContactNames” style=”display:block”>{{Names}}</span>

Complete Web Template Source:

<html lang=”en” xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta charset=”utf-8″ />

function onload() {

// Read Contact names from Span
var spanContactNames = document.getElementById(“spanContactNames”);
if (spanContactNames) {
alert(spanContactNames.innerText);
}
}

</head>
<body onload=”onload()”>
<h1>**Contact Names**</h1>
{% fetchxml settings %}
<fetch version=”1.0″ output-format=”xml-platform” mapping=”logical” distinct=”false”>
<entity name=”contact”>
<attribute name=”fullname” />
<attribute name=”telephone1″ />
<order attribute=”fullname” descending=”false” />
</entity>
</fetch>
{% endfetchxml %}
{% assign result = settings.results.entities %}
{% for item in result %}
{% assign Names = {{item.fullname}} | append: ‘ , ‘ | append: {{Names}} %}
{% endfor %}
<span id=”spanContactNames” style=”display:block”>{{Names}}</span>
</body>
</html>

Note :

  • ‘Liquid Script’ gets executed during the Web Page render and hence the fetched values will be available on Page ‘onload’ script event.
  • ‘Liquid Script’ will respect the Portal security model (i.e., It fetches the records only if you have access granted by your Web Role)

How to test:

  • Create a new Web Template and paste the content to “Source” field.

Liquid Script - 2

  • Add a Web Link and map your Web Template.

πŸ™‚

Advertisements
Categories: ADX Tags: ,