How to set up "forEach" syntax using arrays.

FUJISHIGE,Shuto/藤重 秀斗 0 Reputation points
2024-06-11T01:10:49.8666667+00:00

In the JSON formatting of SharePoint lists, the "forEach" using arrays does not work properly, and the output result becomes blank.

The following is a code sample that does not work properly.

It is really frustrating even though it is a simple thing.

(Output Example)

When the value of the $Content column is "AA//BB//CC", the desired output result is "aaa".

{   
  "$schema": "~~~",
  "elmType": "div", 
  "forEach": "Iterator in split([$Content],'//')",
  "txtContent": "a"
}


SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,150 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,783 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. FUJISHIGE,Shuto/藤重 秀斗 0 Reputation points
    2024-06-11T01:33:30.0233333+00:00

    I solved it myself. I don't know why I need to write this though.

    {
      "$schema": "~~~",
      "elmType": "div",
      "children": [
        {
          "forEach": "Iterator in split([$Content],'//')",
          "elmType": "div",
          "txtContent": "a"
        }
      ]
    }
    
    
    0 comments No comments

  2. Yanli Jiang - MSFT 23,266 Reputation points Microsoft Vendor
    2024-06-11T06:40:13.0833333+00:00

    Hi @FUJISHIGE,Shuto/藤重 秀斗

    Great to know that and thanks for sharing the update here.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others.". and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    [How to set up "forEach" syntax using arrays.]

    Issue Symptom:

    In the JSON formatting of SharePoint lists, the "forEach" using arrays does not work properly, and the output result becomes blank.

    The following is a code sample that does not work properly.

    It is really frustrating even though it is a simple thing.

    (Output Example)

    When the value of the $Content column is "AA//BB//CC", the desired output result is "aaa".

    {   
      "$schema": "~~~",
      "elmType": "div", 
      "forEach": "Iterator in split([$Content],'//')",
      "txtContent": "a"
    }
    

    Current status:

    I solved it myself. I don't know why I need to write this though.

    {
      "$schema": "~~~",
      "elmType": "div",
      "children": [
        {
          "forEach": "Iterator in split([$Content],'//')",
          "elmType": "div",
          "txtContent": "a"
        }
      ]
    }
    

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community members to see the useful information when reading this thread. Thanks for your understanding!

    Have a nice day! :-)