cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Comma Separate the Fetch XML Output and assign the output to a liquid variable

Hello Experts,

 

I have a fetch XML query that gives the list of available organization in the CDS entity. I need to list all the organizations using the fetch XML and separate the fetch XML  output using a comma and then assign it to a liquid variable.

My fetch XML query is as below,

{% fetchxml my_query %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="organization_entity">
<attribute name="organization_entity" />
<order attribute="organization_entity" descending="false" />
<filter type="and">
<condition attribute="organization_entity" operator="not-null" />
</filter>
</entity>
</fetch>
{% endfetchxml %}

{% for result in my_query.results.entities %}
{% assign org = result.organization_entity | join:  "," %}
{% endfor %}
In this case I get the output as:
T, e, s, t, , C, o, m, p, a, n, y, , 1T, e, s, t, , C, o, m, p, a, n, y, , 2
 
I want to get the output as Test Company 1, Test Company 2. and then assign it to a liquid variable. Could anyone please help me on achieving this..
Your help is greatly appreciated.
Thank you
 
1 ACCEPTED SOLUTION

Accepted Solutions
OliverRodrigues
Super User
Super User

Hi you should be able to use the capture Liquid tag:

    {% capture my_variable %}
       {% for result in my_query.results.entities %}
            {{ result.organization_entity }}{% unless forloop.last %},{% endunless %}
        {% endfor %}
    {% endcapture %}
    my_variable --> {{ my_variable }}



If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

3 REPLIES 3
OliverRodrigues
Super User
Super User

Hi, I think you are missing your "name" attribute there. But don't think that's the issue. 

I don't think you need the | join filter there. 

In your loop try something like this:

{% for result in my_query.results.entities %}
    result.organization_entity{% unless forloop.last %},{% endunless %}
{% endfor %}



If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Anonymous
Not applicable

Hi @OliverRodrigues ,

Thank you for your reply.. Could you please let me know how the comma separated value can be assigned to a variable as I need to use that variable again in my code..

Your help is greatly appreciated.

Thank you!

OliverRodrigues
Super User
Super User

Hi you should be able to use the capture Liquid tag:

    {% capture my_variable %}
       {% for result in my_query.results.entities %}
            {{ result.organization_entity }}{% unless forloop.last %},{% endunless %}
        {% endfor %}
    {% endcapture %}
    my_variable --> {{ my_variable }}



If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,593)