Powered By Blogger

Wednesday, October 19, 2022

Power Apps Portal - Split and Concatenate Using Liquid Code

In this blog, I will try to explain how to split values in an array and how we concatenate values using Liquid Code.


Split:

{% assign entityName = entities['entity_logical_name'][request.params.id] %}

The above syntax gets the entity for the passed parameter record id.

Now, Suppose, there is some Single Line of text field present in your Dynamics 365 Dataverse, and this Single Line of Text field stores comma-separated values.

Example: field1 = 1,2,3,4,5.... etc.

Now, I am trying to fetch its value through Liquid Code.

{% if entityName.field1 %}
      {% assign field1_val = entityName.field1 | split: "," %}
{% endif %}

From the above syntax, we can see, firstly I am checking whether field1 is present in the "entityName" entity or not, if this field is present in the "entityName" then we are fetching its value, and then after splitting it by "," storing it in "field1_val" variable.

Now, this "field1_val" variable behaves like an array.

Concatenate:

Now, we will see how can we concatenate more than one value together. We will use the above example. Now we have the "field1_val" array. Also, let us take two strings:

{% assign str1 = 'This is' %}        
{% assign str2 = 'number' %}       

Now, we will loop and print all those numbers one by one along with both strings using "concat".

{% assign finalData = '' %}
{% for val in field1_val%}
   {% assign value = finalData | concat: str1 | concat: {{val}} | concat: str2 | concat: " "%}
   {% assign finalData = value %}
{% endfor %}

Now, if you print finalData, you will get the below Output:

This is 1 number 
This is 2 number 
This is 3 number 
This is 4 number  
This is 5 number ... etc


No comments:

Post a Comment

SQL Queries (SQL4CDS) – Dataverse / Dynamics 365

    1) Get the list of table  with  audit  enabled - SELECT    logicalname,           displayname,           isauditenabled FROM      metada...