array looping function for dynamic layout

I have two CDTs. on the first screen the users select items from the grid and for every selected item I am making a dynamic section to capture details in the myItemDetail_cdt. to create the dynamic layout section I need to know the number of indexes in the array.

I was thinking    1 + enumerate(count(pv!items_cdt)), should give me the count so I know how many items got selected then using type!myItemDetail_cdt() should create a empty array index. what is the looping function to do this? I tried the apply and I have to pass a function.

apply(type!type!myItemDetail_cdt(), 1 + enumerate(count(pv!items_cdt))

  Discussion posts and replies are publicly visible

Parents
  • If i understand your requirements correctly, you're trying to determine list of selected items from grid and display dynamic section for each of the selected item. I would focus on retrieving selected items list from source itemsList used to populate grid and use unique identifier to identify selected item and store them into a local variable.

    Create these expressions to determine selected items and render a dynamic component for each of the selected item.

    1- Expression to get list of selected items:
    index(ri!itemDetails_cdt,
    wherecontains(ri!selectedUniqueIdentifiers, ri!arrayOfIdentifiers),"")


    2 - Expression to display dynamic component for each of the selected item from the grid:
    a!applyComponents(
    function: rule!renderItemDetails,
    array: 1 + enumerate(length(local!itemDetails_cdt)),
    arrayVariable: local!itemTokens
    )

    3 - Create an interface section to display item details, this will be displayed for each item.
    rule!renderItemDetails

    These are just SAMPLE code snippets and make sure to validate data for NULL and perform exception handling wherever required.
  • I don't always have the identifiers for the first array since the users can do a manual entry. so I write the items_Cdt to the database to create a unit id. this unique id is a foreign key in the itemDetails_Cdt.

    what I need is the second cdt the itemDetails_Cdt to have the same length as items_Cdt so I can pass the ri!index to my rule and be able to save the values

    items_Cdt : {{id:1, name.....},{id:2, name......}}
    I need create my second cdt
    itemDetails_Cdt {{},{}} or populated with the foreign key .
    not sure how to do that
    I already have the apply components and my section build. I am just having issue with looping function trying to build my second array before passing into a!applyComponents



    a!applyComponents(
    function: rule!createMyItemDetailSections(,ri!itemDetails_Cdt,_), "I am passing the index for number if rows in the Item_Cdt"

    array: if(
    or(
    isnull(ri!items_Cdt),
    length(ri!items_Cdt)<1
    ),
    {},
    1+enumerate(length(ri!items_Cdt))
    ),
    arrayVariable: local!token
    )



    rule!createMyItemDetailSections:
    input : ri!itemDetails_Cdt
    ri!index

    load(

    with(
    a!sectionLayout(
    firstColumnContents: {

    a!dropdownField(
    label: "my label",
    labelPosition: "ABOVE",
    placeholderLabel: "--- Reason ---",
    choiceLabels: {"a", "b"},
    choiceValues: {"a", "b"},
    value:ri!itemDetail_Cdt[ri!index].reason,
    saveInto: ri!itemDetail_Cdt[ri!index].reason,
    required: true
    )
    ,


    if(ri!itemDetail_Cdt[ri!index].reason = "d",
    load more sections
    ............. {}))
Reply
  • I don't always have the identifiers for the first array since the users can do a manual entry. so I write the items_Cdt to the database to create a unit id. this unique id is a foreign key in the itemDetails_Cdt.

    what I need is the second cdt the itemDetails_Cdt to have the same length as items_Cdt so I can pass the ri!index to my rule and be able to save the values

    items_Cdt : {{id:1, name.....},{id:2, name......}}
    I need create my second cdt
    itemDetails_Cdt {{},{}} or populated with the foreign key .
    not sure how to do that
    I already have the apply components and my section build. I am just having issue with looping function trying to build my second array before passing into a!applyComponents



    a!applyComponents(
    function: rule!createMyItemDetailSections(,ri!itemDetails_Cdt,_), "I am passing the index for number if rows in the Item_Cdt"

    array: if(
    or(
    isnull(ri!items_Cdt),
    length(ri!items_Cdt)<1
    ),
    {},
    1+enumerate(length(ri!items_Cdt))
    ),
    arrayVariable: local!token
    )



    rule!createMyItemDetailSections:
    input : ri!itemDetails_Cdt
    ri!index

    load(

    with(
    a!sectionLayout(
    firstColumnContents: {

    a!dropdownField(
    label: "my label",
    labelPosition: "ABOVE",
    placeholderLabel: "--- Reason ---",
    choiceLabels: {"a", "b"},
    choiceValues: {"a", "b"},
    value:ri!itemDetail_Cdt[ri!index].reason,
    saveInto: ri!itemDetail_Cdt[ri!index].reason,
    required: true
    )
    ,


    if(ri!itemDetail_Cdt[ri!index].reason = "d",
    load more sections
    ............. {}))
Children