Update List of Lists based on condition

Hi All,

I have the following scenario: 

which basically says:

List of Dictionary: 3 items

  Dictionary

    class: "1"

    sections: List of Text String: 4 items

      "a"

      "b"

      "c"

      "d"

  Dictionary

    class: "2"

    sections: List of Text String: 3 items

      "a"

      "b"

      "c"

  Dictionary

    class: "3"

    sections: List of Text String: 5 items

      "a"

      "b"

      "c"

      "d"

      "e"

------------------------------------------------------------------------------------------------------------------------

I want to update and return this list of classes such that the sections ("d", "e") are removed from the sections list for each class. How can we implement it? And what could be the optimum algorithm for Appian to implement. 

Note: I want to implement similar logic to a list of CDTs (datasubset) which has nested CDTs list based on condition.

  Discussion posts and replies are publicly visible

  • Hello soumyab243,

    There are two ways to get the desired result.

    1. Using the forEach() and constructing the required CDT which is quite tedious if the CDT is having more attributes.

    load(
    /* Your CDT */
    local!tempVar: {
    {
    class: "1",
    sections: {
    "a",
    "b",
    "c",
    "d"
    }
    },
    {
    class: "2",
    sections: {
    "a",
    "b",
    "c"
    }
    },
    {
    class: "3",
    sections: {
    "a",
    "b",
    "c",
    "d",
    "e"
    }
    }
    },
    /* Elements to be Removed */
    local!tempSections: {
    "d",
    "e"
    },
    /* Result */
    /* You need to manually construct the CDT here which is quite tedious if your CDT is having more attributes */
    a!forEach(
    items: local!tempVar,
    expression: {
    class: fv!item.class,
    sections: remove(
    fv!item.sections,
    wherecontains(
    local!tempSections,
    touniformstring(
    {
    fv!item.sections
    }
    )
    )
    )
    }
    )
    )

    2. Using forEach() with updatecdt() function. I would prefer this since we don't have to construct the CDT structure and we can focus only on the attributes we are interested in. updatecdt() is a part of the shared component CDT Manipulation.

    load(
    /* Your Data */
    local!tempVar: {
    {
    class: "1",
    sections: {
    "a",
    "b",
    "c",
    "d"
    }
    },
    {
    class: "2",
    sections: {
    "a",
    "b",
    "c"
    }
    },
    {
    class: "3",
    sections: {
    "a",
    "b",
    "c",
    "d",
    "e"
    }
    }
    },
    /* Elements to be removed */
    local!tempSections: {
    "d",
    "e"
    },
    /* Using forEach() and updatecdt()*/
    a!forEach(
    items: local!tempVar,
    expression: updatecdt(
    cdt: fv!item,
    fieldsAndValue: {
    sections: {
    remove(
    fv!item.sections,
    wherecontains(
    {
    "d",
    "e"
    },
    touniformstring(
    {
    fv!item.sections
    }
    )
    )
    )
    }
    }
    )[1]
    )
    )

     

    Hope this helps!

  • 0
    Certified Lead Developer

    Hi soumyab243 you can use following logic to achieve your requirements as mentioned below:

    load(
      local!data: {
        {
      		class: "1",
      		sections: {"a", "b", "c", "d"}
      	},
      	{
      		class: "2",
      		sections: {"a", "b", "c"}
      	},
      	{
      		class: "3",
      		sections: {"a", "b", "c", "d", "e"}
      	}
      },
      a!forEach(
        local!data,
        {
          class: fv!item.class,
          sections: difference(trim(split(touniformstring(fv!item.sections), ";")), {"d", "e"})
          
        }
      )
    )

    Hope this will help you.