Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Error Trying to Execute FetchXML in Portal Web Template

Posted on by 70

I am trying to create a custom chart for display in a dashboard in the portal, but I am getting the following error on the portal dashboard: 

[ Liquid error: Exception has been thrown by the target of an invocation. ]

Below is the code in the web template for the dashboard page.  I tried commenting out the code specific to the chart, and the part of the code that triggers the error is the for loop after the end fetch: {% for item in feed.results.entities %}.  Does anyone have any ideas what might be wrong or how to debug this?

...

<div class="col-md-6 hide-chart-legend">
<!-- Opportunities -->
<!--{% chart id:"19A46D6C-82C6-E811-A95D-000D3A3ACDE0" viewid:"1FDF0A3F-856C-E711-8105-E0071B711C21" %}-->
{% fetchxml feed %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" aggregate="true">
<entity name="opportunity">
<attribute name="name" alias="opp_count" aggregate="countcolumn"/>
<attribute name="new_travelyearglobal" />
<attribute name="new_productlineglobal" />
<attribute name="opportunityid" />
<attribute name="new_atacoach" alias="new_atacoach" groupby="true"/>
<filter type="and">
<condition attribute="new_atacoach" operator="eq" value="{{ user.contactid }}" />
</filter>
</entity>
</fetch>
{% endfetchxml %}[
{% for item in feed.results.entities %}
{
"count": "{{ item.opp_count }}",
"owner": " {{ item.new_atacoach.name }}",
"ownerid": "{{ item.new_atacoach.id | escape }}",
"travelyear" : "{{ item.new_travelyearglobal.label }}"
}
{% unless forloop.last %},{% endunless %}
{% endfor -%}
]

<canvas id="opportunityCountByOwnerAndTravelYear"></canvas>
<script src="//cdnjs.cloudfare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
$(function(){
$.ajax({
method: "GET",
url: "/opportunitiesbyownerandtravelyearjson/"
})
.done (function(){
var labels = [], datavalues = [];
for (i = 0; i < results.length; i++)
{
labels.push(results[i].owner);
datavalues.push(parseFloat(results[i].count));
}

var dataobj = {
labels: labels,
datasets: [{
data: countdata
}]
}
});

var ctx = $("#opportunityCountByOwnerAndTravelYear");
var opportunityCountByOwnerAndTravelYear = new Chart(ctx, {
type: 'column',
data: dataobj,
options: {
animation: {
animateScale: true
};
legend: {
display: true,
position: "bottom"
}
}
});

});
</script>
</div>

...

*This post is locked for comments

  • Suggested answer
    Dmytro Rutkovskyi Profile Picture
    Dmytro Rutkovskyi 1,835 on at
    RE: Error Trying to Execute FetchXML in Portal Web Template

    I think the problem itself not Portal related but rather FetchXML related.

    When you group by you can only include the attribute which you are using with groupby keyword or with aggregate function.

    I suggest test fetchXML query independently from the Portal, for example using fetchXML builder plugin of XrmToolbox (https://fxb.xrmtoolbox.com/)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans