0

Populate Word - hide blank table rows / entire tables

Hello,

 

I am using the Encodian Populate Word Template, and my users biggest ask has been is there a way to remove tables that are blank in my word templates. Right now, I have a template with a lot of tables that may or may not be filled based on the entry. Is there an Encodian connector that can help me automate more of that process?

 

Thanks,

George

4 comments

  • Avatar
    Jay Goodison Official comment

    Hi George Stredny

    Note, this is already possible using Enumeration Extension Methods, in particular the Any() function to check for Null arrays. This is also described here: Repeating Content – Checking for Null Arrays

    By way of example, I have the following JSON with the contracts array being empty:

    {
      "companyName": "Encodian",
      "contracts": []
    }

    In my word template, I have a table that usually takes values from the contracts array. Knowing that this could be empty, I have wrapped the table in a conditional expression with the condition being the Any() enumeration extension.

    Populating this template using the JSON provided will return a blank space with no table.

    Let us know if you have any other questions.

     

    Edited by Jay Goodison
  • 0
    Avatar
    George Stredny

    Ok thank you Jay. So my tables aren't repeating rows. They look more like:

    Would I then need an if statement for each row in this table? And the Any() function will delete the rows that are null? I have scenarios where some rows are empty and even the entire table is empty, so I would want the rows deleted in the table and/or the entire table to be removed from the word document.

  • 0
    Avatar
    Jay Goodison

    George Stredny - thanks for clarifying your scenario. This too is possible.

    There are two checks you need. 

    1. Row by row conditional expression
    2. Entire table conditional expression

    Row by row:

    Take this sample JSON

    {
    "Name":"",
    "Surname":"",
    "Job":"",
    "City":"London"
    }

    The table template syntax below checks whether each value is null and excludes the row if the value is null.

    The above JSON and above template provide this result:

     

    Entire table conditional logic

    Lastly, you need an overall check whether ALL the values in the table are null and wrap the entire table in the conditional statement. You can do this check in the template but in this case, I would suggest checking values in Power Automate would be easier.

    Simply add a boolean to your JSON data using a condition:

    If all items are "", then set the boolean to TRUE.

    Your JSON would look like this:

    {
    "Name":"",
    "Surname":"",
    "Job":"",
    "City":"",
    "Table1Boolean":"BOOLEAN VALUE"
    }

    And your template like this:

    NOTE: my spacing between the tables and the opening closing merge tags would need adjusting so you do not get lots of white space if you have multiple tables that end up not being inserted.

     

     

    Edited by Jay Goodison
  • 0
    Avatar
    George Stredny

    Great thank you!

Please sign in to leave a comment.