Test

Here is the use case  Name1 is the section names value1 is the text value,when next section name starts with item2 before empty section names consider as section names with the text followed by as mentioned  in the output 

a!localVariables(
  local!testdata: {
    { "Name1": "Item1", "Value1": "Data for Item 1" },
    { "Name1": null, "Value1": "Different data for Item 2" },
    { "Name1": null, "Value1": "Some other kind of data" },
    { "Name1": "Item2", "Value1": "Another example of data" },
    { "Name1": null, "Value1": "Random data like GBP 50,000" },
    { "Name1": "Item3", "Value1": "Data related to an event or value" },
    { "Name1": null, "Value1": "Adjustable by percentage of revenue" },
    { "Name1": null, "Value1": "Premium payable quarterly" }
  },
  
  local!testdata


expected output is 

[
{ "section": "Item1", "fullText": "Data for Item 1 Different data for Item 2 Some other kind of data" },
{ "section": "Item2", "fullText": "Another example of data Random data like GBP 50,000" },
{ "section": "Item3", "fullText": "Data related to an event or value Adjustable by percentage of revenue Premium payable quarterly" }
]

@Stefan Helzle      

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Senior Developer

    Hi  

    a!localVariables(
      local!testdata: {
        {
          "Name1": "Item1",
          "Value1": "Data for Item 1"
        },
        {
          "Name1": null,
          "Value1": "Different data for Item 2"
        },
        {
          "Name1": null,
          "Value1": "Some other kind of data"
        },
        {
          "Name1": "Item2",
          "Value1": "Another example of data"
        },
        {
          "Name1": null,
          "Value1": "Random data like GBP 50,000"
        },
        {
          "Name1": null,
          "Value1": "Hii data like GBP 50,000"
        },
        {
          "Name1": "Item3",
          "Value1": "Data related to an event or value"
        },
        {
          "Name1": null,
          "Value1": "Adjustable by percentage of revenue"
        },
        {
          "Name1": null,
          "Value1": "Premium payable quarterly"
        },
        {
          "Name1": null,
          "Value1": "party payable quarterly"
        },
        {
          "Name1": "Item4",
          "Value1": "Item four data"
        }
      },
      local!uniqueName: reject(
        fn!isnull,
        union(
          local!testdata.Name1,
          local!testdata.Name1
        )
      ),
      local!indexes: a!forEach(
        items: enumerate(length(local!uniqueName)) + 1,
        expression: a!localVariables(
          local!first: index(local!uniqueName, fv!item, {}),
          local!second: index(local!uniqueName, fv!item + 1, null),
          if(
            a!isNullOrEmpty(local!second),
            {},
            a!map(
              startIndex: index(
                wherecontains(
                  tostring(local!first),
                  touniformstring(local!testdata.Name1)
                ),
                1,
                ""
              ),
              endIndexPlusOne: index(
                wherecontains(
                  tostring(local!second),
                  touniformstring(local!testdata.Name1)
                ),
                1,
                ""
              )
            )
          )
        )
      ),
      local!finalNameStartIndex: local!indexes[length(local!indexes)].endIndexPlusOne,
      a!flatten(
        {
          a!forEach(
            items: local!indexes,
            expression: a!map(
              section: index(
                local!testdata.Name1,
                fv!item.startIndex,
                ""
              ),
              fullText: joinarray(
                index(
                  local!testdata.Value1,
                  enumerate(
                    tointeger(fv!item.endIndexPlusOne) - fv!item.startIndex
                  ) + fv!item.startIndex,
                  ""
                ),
                " "
              )
            )
          ),
          a!map(
            section: index(
              local!testdata.Name1,
              local!finalNameStartIndex,
              ""
            ),
            fullText: joinarray(
              index(
                local!testdata.Value1,
                {
                  enumerate(
                    length(local!testdata) - local!finalNameStartIndex + 1
                  ) + local!finalNameStartIndex
                },
                ""
              ),
              " "
            )
          )
        }
      )
    )

    Hope it helps. please test it with some scenarios; let me know is it working fine

Reply
  • +1
    Certified Senior Developer

    Hi  

    a!localVariables(
      local!testdata: {
        {
          "Name1": "Item1",
          "Value1": "Data for Item 1"
        },
        {
          "Name1": null,
          "Value1": "Different data for Item 2"
        },
        {
          "Name1": null,
          "Value1": "Some other kind of data"
        },
        {
          "Name1": "Item2",
          "Value1": "Another example of data"
        },
        {
          "Name1": null,
          "Value1": "Random data like GBP 50,000"
        },
        {
          "Name1": null,
          "Value1": "Hii data like GBP 50,000"
        },
        {
          "Name1": "Item3",
          "Value1": "Data related to an event or value"
        },
        {
          "Name1": null,
          "Value1": "Adjustable by percentage of revenue"
        },
        {
          "Name1": null,
          "Value1": "Premium payable quarterly"
        },
        {
          "Name1": null,
          "Value1": "party payable quarterly"
        },
        {
          "Name1": "Item4",
          "Value1": "Item four data"
        }
      },
      local!uniqueName: reject(
        fn!isnull,
        union(
          local!testdata.Name1,
          local!testdata.Name1
        )
      ),
      local!indexes: a!forEach(
        items: enumerate(length(local!uniqueName)) + 1,
        expression: a!localVariables(
          local!first: index(local!uniqueName, fv!item, {}),
          local!second: index(local!uniqueName, fv!item + 1, null),
          if(
            a!isNullOrEmpty(local!second),
            {},
            a!map(
              startIndex: index(
                wherecontains(
                  tostring(local!first),
                  touniformstring(local!testdata.Name1)
                ),
                1,
                ""
              ),
              endIndexPlusOne: index(
                wherecontains(
                  tostring(local!second),
                  touniformstring(local!testdata.Name1)
                ),
                1,
                ""
              )
            )
          )
        )
      ),
      local!finalNameStartIndex: local!indexes[length(local!indexes)].endIndexPlusOne,
      a!flatten(
        {
          a!forEach(
            items: local!indexes,
            expression: a!map(
              section: index(
                local!testdata.Name1,
                fv!item.startIndex,
                ""
              ),
              fullText: joinarray(
                index(
                  local!testdata.Value1,
                  enumerate(
                    tointeger(fv!item.endIndexPlusOne) - fv!item.startIndex
                  ) + fv!item.startIndex,
                  ""
                ),
                " "
              )
            )
          ),
          a!map(
            section: index(
              local!testdata.Name1,
              local!finalNameStartIndex,
              ""
            ),
            fullText: joinarray(
              index(
                local!testdata.Value1,
                {
                  enumerate(
                    length(local!testdata) - local!finalNameStartIndex + 1
                  ) + local!finalNameStartIndex
                },
                ""
              ),
              " "
            )
          )
        }
      )
    )

    Hope it helps. please test it with some scenarios; let me know is it working fine

Children