Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM KB Portal liquid fetchxml not working as expected

Posted on by

Hi!

Im trying out the Knowledge Base portal for CRM online. I encountered the following a problem i cant figure out:

I have the following code (fetchxml) in a webtemplate

{% fetchxml categories_query %}
  <fetch count="{{ count }}" aggregate="true" returntotalrecordcount="true" >
    <entity name="category" >
      <attribute name="categorynumber" alias="categorynumber" groupby="true" />
      <attribute name="parentcategoryid" alias="parentcategoryid" groupby="true" />
      <attribute name="title" alias="title" groupby="true" />
      <order alias="parentcategoryid" />
      <order alias="title" />
      <link-entity name="knowledgearticlescategories" from="categoryid" to="categoryid" link-type="outer" >
        <attribute name="categoryid" alias="categoryid" groupby="true" />
        <attribute name="knowledgearticleid" alias="kb_count" aggregate="count" />
      </link-entity>
    </entity>
  </fetch>
{% endfetchxml %}

In theory this should give me back all my categories for the KB articles with the count of the associated articles for each category. Something like this:

XRMToolboxResult.png

Actually this gives back the count wrong, because of the outer join, but where the categoryid id null, there i know the actual kb_count is 0. Thats not the problem.

The problem is when i insert this in to a page, i got back something like this:

3results.png

Like the liquid parser just ignores the link-type="outer" part, and it gets data with a simple join on the entities.

How can i get back all the expected data?

*This post is locked for comments

  • csonthejjas Profile Picture
    csonthejjas on at
    RE: CRM KB Portal liquid fetchxml not working as expected

    Hi Tom, and thanks for your responds!

    I cant follow the logic behinde this.

    If i select the count of articles first than the categories with zero articles are already closed out of the result.

    (In the switching table there are no records for for categories with non existing article assocciations -> means nothing to catch to count as 0)

    Can you please give the fetchxml you thinking of? Maybe im just missing something here...

  • ThomasN Profile Picture
    ThomasN 3,190 on at
    RE: CRM KB Portal liquid fetchxml not working as expected

    What if you switched the kbarticles and categories. It seems you are grouping categories, and then looking for a count of articles. Try looking for the count of articles group those by category. Sort of flip it. I hope I am making sense.

  • csonthejjas Profile Picture
    csonthejjas on at
    RE: CRM KB Portal liquid fetchxml not working as expected

    Hi Tom!

    Thanks for the reply, and sorry if my initial post was unclear about my problem.

    So:

    1) Yes the goal is to get all categories with an article count accociated with given category

    2) My expected result you can see on the first attached picture (made with XRMTool's FetchXML builder)

    3) Yes i tried, as you can see in the inserted fetchXML code, im using the  link-type="outer" for the link-entity

    4) The solution i'm looking for is to get the expected data(first picture) instead of the data you can see on second picture in initial post

    5) Here is the full webtemplate code im using and getting the result on second picture

    {% assign count = count | default: 100 %}
    {% assign category_url = sitemarkers['Category'].url %} 
    <div class="panel panel-default">
      {% fetchxml categories_query %}
      <fetch count="{{ count }}" aggregate="true" returntotalrecordcount="true" >
        <entity name="category" >
          <attribute name="categorynumber" alias="categorynumber" groupby="true" />
          <attribute name="parentcategoryid" alias="parentcategoryid" groupby="true" />
          <attribute name="title" alias="title" groupby="true" />
          <order alias="title" />
          <link-entity name="knowledgearticlescategories" from="categoryid" to="categoryid" link-type="outer" >
            <attribute name="categoryid" alias="categoryid" groupby="true" />
            <attribute name="knowledgearticleid" alias="kb_count" aggregate="count" />
          </link-entity>
        </entity>
      </fetch>
      {% endfetchxml %}
      
      {% assign categories = categories_query.results.entities %}  
      {% if categories %}
        <div>count: {{ count }}</div>
        <div>categories.size: {{ categories.size }}</div>
        <div class="list-group"> 
        {% for category in categories %}
          <a class="list-group-item" href="{{ category_url | add_query: 'id', category.categorynumber | escape }}">
            {{ category.title | escape }} ({{category.kb_count}})
          </a>
          
        {% endfor %}
        </div>
      {% endif %}
    </div>


    6) Is there any solution or workaround to get the right data? Or is this a bug?

    
    
  • ThomasN Profile Picture
    ThomasN 3,190 on at
    RE: CRM KB Portal liquid fetchxml not working as expected

    Hi Csonthejjas, thanks for reaching out.

    Can you clarify for us? Your FetchXml is looking for a count of all categories that are used in the knowledgearticlescategories entity.

    What is the expected data set you are looking for? Have you looked at using a left outer join if you want to see all categories not just ones used in kbarticles?

    msdn.microsoft.com/.../dn531006.aspx

    Let me know how to help.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans