Am looking for an example i.e, am selecting values from checkbox. values are in hierarchy like global value(main), multiple parent and multiple child values. when I select a particular child then parent of that child value need to be selected automatically even the global value also. whenever I select the parent then global value need to be selected automatically.
Discussion posts and replies are publicly visible
You can achieve this using index() and wherecontains() functions. See below a sample code snippet. I have used 3 levels of hierarchy here -
level 1 - Global
level 2 - Categories
level 3 - Sub-Categories
a!localVariables( local!global: { {id: 1, label: "Global 1"}, {id: 2, label: "Global 2"}, {id: 3, label: "Global 3"} }, local!categories: { {id: 1, label: "Category 1", globalId: 1}, {id: 2, label: "Category 11", globalId: 1}, {id: 3, label: "Category 111", globalId: 1}, {id: 4, label: "Category 2", globalId: 2}, {id: 5, label: "Category 22", globalId: 2}, {id: 6, label: "Category 222", globalId: 2}, {id: 7, label: "Category 3", globalId: 3}, {id: 8, label: "Category 33", globalId: 3}, {id: 9, label: "Category 333", globalId: 3} }, local!subCategories: { {id: 1, label: "Sub 1.a", categoryId: 1}, {id: 2, label: "Sub 1.b", categoryId: 1}, {id: 3, label: "Sub 11.a", categoryId: 2}, {id: 4, label: "Sub 11.b", categoryId: 2}, {id: 5, label: "Sub 111.a", categoryId: 3}, {id: 6, label: "Sub 111.b", categoryId: 3}, {id: 7, label: "Sub 2.a", categoryId: 4}, {id: 8, label: "Sub 2.b", categoryId: 4}, {id: 9, label: "Sub 22.a", categoryId: 5}, {id: 10, label: "Sub 22.b", categoryId: 5}, {id: 11, label: "Sub 222.a", categoryId: 6}, {id: 12, label: "Sub 222.b", categoryId: 6}, {id: 13, label: "Sub 3.a", categoryId: 7}, {id: 14, label: "Sub 3.b", categoryId: 7}, {id: 15, label: "Sub 33.a", categoryId: 8}, {id: 16, label: "Sub 33.b", categoryId: 8}, {id: 17, label: "Sub 333.a", categoryId: 9}, {id: 18, label: "Sub 333.b", categoryId: 9}, }, local!selectedGlobalValues, local!selectedCategories, local!selectedSubCategories, a!columnsLayout( columns: { a!columnLayout( contents: { a!checkboxField( label: "Global", choiceLabels: index(local!global, "label", {}), choiceValues: index(local!global, "id", {}), value: local!selectedGlobalValues, saveInto: { local!selectedGlobalValues, /* Update Categories based on current parent selections */ a!save( local!selectedCategories, index( index(local!categories, "id", {}), wherecontains( tointeger(local!selectedGlobalValues), tointeger(index(local!categories, "globalId", {})) ), {} ) ), /* Update Sub-categories based on current parent selections */ a!save( local!selectedSubCategories, index( index(local!subCategories, "id", {}), wherecontains( tointeger(local!selectedCategories), tointeger(index(local!subCategories, "categoryId", {})) ), {} ) ) } ) } ), a!columnLayout( contents: { a!checkboxField( label: "Categories", choiceLabels: index(local!categories, "label", {}), choiceValues: index(local!categories, "id", {}), value: local!selectedCategories, saveInto: { local!selectedCategories, /* Update Sub-categories based on current category selections */ a!save( local!selectedSubCategories, index( index(local!subCategories, "id", {}), wherecontains( tointeger(local!selectedCategories), tointeger(index(local!subCategories, "categoryId", {})) ), {} ) ), /* Update Global (parent) based on current category selections */ a!save( local!selectedGlobalValues, index( index(local!categories, "globalId", {}), wherecontains( tointeger(local!selectedCategories), tointeger(index(local!categories, "id", {})) ), {} ) ) } ) } ), a!columnLayout( contents: { a!checkboxField( label: "Sub-Categories", choiceLabels: index(local!subCategories, "label", {}), choiceValues: index(local!subCategories, "id", {}), value: local!selectedSubCategories, saveInto: { local!selectedSubCategories, /* Update Categories (1st level parent) based on current sub-category selections */ a!save( local!selectedCategories, index( index(local!subCategories, "categoryId", {}), wherecontains( tointeger(local!selectedSubCategories), tointeger(index(local!subCategories, "id", {})) ), {} ) ), /* Update Global (2nd level parent) based on current sub-category selections */ a!save( local!selectedGlobalValues, index( index(local!categories, "globalId", {}), wherecontains( tointeger(local!selectedCategories), tointeger(index(local!categories, "id", {})) ), {} ) ) } ) } ) } ) )
Thank you for the answer. And this can be included in the expression rule and call it in a grid or do i need to create a process model for it and call it grid. if it is how can i do that