0

Nested foreach statements - Populate Word Document

I am to create a document from two SharePoint lists.  One list contains category headings of Violations.  The other list contains descriptions for different levels of those violations. 

 

Here is my template:

<<foreach [violation in violations]>>Violation: <<[violation.viol]>> 

  • <<foreach [nature in violation.natures]>><<[nature.item]>> 

<</foreach>> 

<</foreach>> 

The Json format from the input step of the populate Word Document action is below:

[
  {
    "viol": "Dilution in Lieu of Treatment",
    "definition": "Dilution occurs when an IU adds water to their effluent for the purpose of decreasing the concentration of measured pollutants in order to meet pretreatment standards.",
    "basepts": "1",
    "natures": [
      {"item": "Unaware"},
      {"item": "NA"},
      {"item": "NA"},
      {"item": "Intentional"}
    ]
  },
  {
    "viol": "Discharge of Hazardous Waste",
    "definition": "Discharge of waste or wastewater that meets the definition of a RCRA Hazardous Waste into the POTW's collection system without prior approval from the CA.",
    "basepts": "1",
    "natures": [
      {"item": "Unaware"},
      {"item": "NA"},
      {"item": "NA"},
      {"item": "Intentional"},
      {"item": "User unaware of discharge or unware of RCRA status"},
      {"item": "User aware of discharge and failed to report."}
    ]
  },
  {
    "viol": "Failure to Comply with Corrective Action",
    "definition": "Related to other enforcement mechanisms previously issued which requires corrective action. Corrective actions may be communicated in NOVs or other less formal enforcement mechanisms including inspection reports. Does not apply to compliance schedules (e.g., issued in control mechanisms, consent or compliance orders; see Compliance Schedule Milestone).",
    "basepts": "0",
    "natures": [
      {"item": "Unaware"},
      {"item": "NA"},
      {"item": "NA"},
      {"item": "Intentional"},
      {"item": "User unaware of discharge or unware of RCRA status"},
      {"item": "User aware of discharge and failed to report."},
      {"item": "Equivalent interim measure implemented"},
      {"item": "Interim measure implemented, only partially adequate to resolve deficiency"},
      {"item": "No interim measure implemented"},
      {"item": "Corrective action ignored"}
    ]
  }
]

 

However, i get the following error:

Error! Can not get the value of member 'item' on type 'System.Char'

I've tried Allowing Missing Values, and it finds the viol value, but the items in the bullet points are blank (and it generates 1100 pages of them).

 

I've also tried the following template with the same results:

<<foreach [violation in violations]>>Violation: <<[violation.viol]>> 

  • <<foreach [nature in natures]>><<[nature.item]>> 

<</foreach>> 

<</foreach>> 

 

2 comments

  • Avatar
    Jo Hall Official comment

    Hi Tony,

    Your JSON appears to have been truncated so based on what you have said I expanded it to and couldn't replicate your issue:  (i've added the bold pieces) 

    {
         "violations": [
              {
                   "viol": "Dilution in Lieu of Treatment",
                   "definition": "Dilution occurs when an IU adds water to their effluent for the purpose of decreasing the concentration of measured pollutants in order to meet pretreatment standards.",
                   "basepts": "1",
                   "natures": [
                        { "item": "Unaware" },
                        { "item": "NA" },
                        { "item": "NA" },
                        { "item": "Intentional" }
                   ]
              },
              {
                   "viol": "Discharge of Hazardous Waste",
                   "definition": "Discharge of waste or wastewater that meets the definition of a RCRA Hazardous Waste into the POTW's collection system without prior approval from the CA.",
                   "basepts": "1",
                   "natures": [
                        { "item": "Unaware" },
                        { "item": "NA" },
                        { "item": "NA" },
                        { "item": "Intentional" },
                        { "item": "User unaware of discharge or unware of RCRA status" },
                        { "item": "User aware of discharge and failed to report." }
                   ]
              },
              {
                   "viol": "Failure to Comply with Corrective Action",
                   "definition": "Related to other enforcement mechanisms previously issued which requires corrective action. Corrective actions may be communicated in NOVs or other less formal enforcement mechanisms including inspection reports. Does not apply to compliance schedules (e.g., issued in control mechanisms, consent or compliance orders; see Compliance Schedule Milestone). ",
                   "basepts": "0",
                   "natures": [
                        { "item": "Unaware" },
                        { "item": "NA" },
                        { "item": "NA" },
                        { "item": "Intentional" },
                        { "item": "User unaware of discharge or unware of RCRA status" },
                        { "item": "User aware of discharge and failed to report." },
                        { "item": "Equivalent interim measure implemented" },
                        { "item": "Interim measure implemented, only partially adequate to resolve deficiency" },
                        { "item": "No interim measure implemented" },
                        { "item": "Corrective action ignored" }
                   ]
              },
              {
                   "viol": "Failure to Follow BMPs",
                   "definition": "Industrial User has failed to follow all or part of a Best Management Practice required by their permit or alternative control mechanism. Includes failure to properly implement the facility's slug discharge control plan.",
                   "basepts": "0"
              }        
         ]
    }

    This worked perfectly for me with your original template (although both do work) 

    <<foreach [violation in violations]>>Violation: <<[violation.viol]>> 

    • <<foreach [nature in violation.natures]>><<[nature.item]>> 

    <</foreach>> 

    <</foreach>> 

    Giving:

     

  • 0
    Avatar
    Tony

    Just wanted to follow-up here.  The JSON I posted was formatted in copilot and it truncated it.  It also didn't pass my actual issue through.

    When i was adding the "natures" nested array inside my "violations" array, i had included quotes around the variable in power automate.  It was seeing that portion of the JSON as text.

     

    Thanks for the help

Please sign in to leave a comment.