Liquid Mapping Tips

  • Lookup a value on a table:

Template: {{ 'value' | dbLookup: 'table_name','field_name' }}

Example: find the record has product code Z0001

{
"product":{{ 'Z00001' | dbLookup: 'as_inventory','product_code' }}
}

  • Subtract a string from letter

{{ 'string' | subtractRight: '-' }}

{{ 'string' | subtractLeft: '-' }}

Example:

{{ '12345-12' | subtractRight: '-' }} >> result: 12345

{{ '12345-12' | subtractLeft: '-' }} >> result: 12

  • Call multiple APIs to get response for mapping

"targetList": [
{
"name":"prline",
"method": "API",
"api": {
"url": "api url",
"authenticationType": "Bearer",
"token":"123",
"method": "GET",
"headers": {
"Content-Type": "application/json",
"tenantID": "657d0fa69ab9a5dba703f185"
}
}
}

 

The data will be combined for mapping:
{

"raw": from raw data,

"prline": from response of api

}

  • Get a field has comma

Template: jsonData['field_name']
example: jsonData['@odata.context'] from json:

{

  "@odata.context":"value"

}

 

jsonData['raw']['@odata.context'] from json:
{

"raw":

{

  "@odata.context":"value"

}

}

  • Loop the array in json

{% for item in data.items %}

    "itemName": "{{item.name}}"

{% endfor %}

  • If else condition

{% if Vendor_Shipment_No != ''%}
    "Document_Type": "Purchase Order",
{% else %}
    "Document_Type": "PO Creation",
{% endif %}

  • Validation and throw error message

Use special field name: allsyncError

{% if store_code==null or store_code==''%}
     "allsyncError":"store_code is blank",
{% endif %}

  • Last record in loop

{% for item in data.items %}

    "itemName": "{{item.name}}"

{% if forloop.last == false %},{% endif %}
{% endfor %}

{% endfor %}

  •  Index in loop

{% for item in data.items %}

    "sequence": {{forloop.index}}

{% endfor %}

  •  Size of an array

{% if value.size>0 %}
        "Line_No":"{{value.first.Line_No}}"
{% else %}

  • Convert timestamp to date string

"Posting_Date": "{{CREATED_DATE | date: "%Y-%m-%d"}}"

  • Convert datetime string to timestamp:

"order_date": {{created_at | date: '%s'}}

  • Minus, multiply:

"line_total": {{product.price | times: product.quantity | minus: product.total_discount}}

  • Encryption

{{ subject | sha256 }} : not able to decrypt

{{ subject | aesEncode: 'key 32 character' }}  : method AES_GCM

Back to blog