Skip to main content
Question

Pipeline Logic

  • July 17, 2023
  • 0 replies
  • 92 views

I have made a scheduled pipeline that will make a request to a table and send an email with the correct formatting. All of this is working correctly, however, if the table is blank the pipeline is still sending a blank email with just the field headers, how can I make a decision with the pipelines so if the table is blank it does not send an email? 

Pipeline:

I also tried to send a message saying all caught up if there were no records in the table, but then it does not format the table correctly if it is not blank.

Modified code:

<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}
th, td {
  padding: 15px;
}
</style>
<h2>Report Name</h2>
{% if a.json.data|length > 0 %}
    <table>
    <tr>
    {# Loop through the Fields object to create the table headers #}
    {% for object in a.json.fields %}
            <th>{{object['label']}}</th>
    {% endfor %}
    </tr>
    {# Loop through the records and create a row #}
    {% for record in a.json.data %}
    <tr>
    {# Loop though fields #}
    {% for field in a.json.fields %}
            {# Grab the records field data and format based on Field Type #}
            {% if field['type'] == 'percentage' %}
                  <td>{{"{:,.2f}%".format(record[field['id'] | string]['value'] | float * 100)}}</td>
            {% elif field['type'] == 'currency' %}
                  <td>{{"${:,.2f}".format(record[field['id'] | string]['value'] | float)}}</td>
            {% elif field['type'] == 'user' %}
                  {# Retrieve the user's name from the 'user' field #}
                  {% set user_data = record[field['id'] | string]['value'] %}
                  {% set user_name = user_data['name'] %}
                  <td>{{ user_name }}</td>
            {% else %}
                  <td>{{record[field['id'] | string]['value']}}</td>
            {% endif %}
    {% endfor %}
    </tr>
    {% endfor %}
    </table>
{% else %}
  <p>All Time Entries Approved</p>
{% endif %}

Original Code that works fine:

<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}
th, td {
  padding: 15px;
}
</style>
<h2>Report Name</h2>
<table>
<tr>
{# Loop through the Fields object to create the table headers #}
{% for object in a.json.fields %}
    <th>{{object['label']}}</th>
{% endfor %}
</tr>
{# Loop through the records and create a row #}
{% for record in a.json.data %}
<tr>
{# Loop though fields #}
{% for field in a.json.fields %}
    {# Grab the records field data and format based on Field Type #}
    {% if field['type'] == 'percentage' %}
      <td>{{"{:,.2f}%".format(record[field['id'] | string]['value'] | float * 100)}}</td>
    {% elif field['type'] == 'currency' %}
      <td>{{"${:,.2f}".format(record[field['id'] | string]['value'] | float)}}</td>
    {% elif field['type'] == 'user' %}
      {# Retrieve the user's name from the 'user' field #}
      {% set user_data = record[field['id'] | string]['value'] %}
      {% set user_name = user_data['name'] %}
      <td>{{ user_name }}</td>
    {% else %}
      <td>{{record[field['id'] | string]['value']}}</td>
    {% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>



------------------------------
William Hunter
------------------------------
This topic has been closed for replies.

Forum|alt.badge.img+9
  • Registered
  • July 17, 2023

You should be able to evaluate with an if condition where json.data.length is greater than 0, then send the email. So instead of request/send email you would do request / if condition json.data.length > 0 / send email thus you'd only be sending an email when at least one record is returned. 



------------------------------
Chayce Duncan
------------------------------