Home > ADX > Liquid script to fetch Contact names – Dynamics Portals SaaS

Liquid script to fetch Contact names – Dynamics Portals SaaS

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.

🙂

Advertisement
Categories: ADX Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: