a!localVariables( local!selectedPermission, local!selectedArea, local!selectedComponent, local!selectedDepartment, local!departments: a!refreshVariable( value: rule!MECMS_getDepartmentList(activeFilter: true), refreshOnVarChange: { ri!refreshInt } ), local!area: a!refreshVariable( value: if( rule!APN_isBlank(local!selectedPermission), null, rule!MECMS_getRefArea( selections: {"id", "value"}, permissionId: local!selectedPermission, pagingInfo: a!pagingInfo(startIndex: 1, batchSize: - 1) ).data ), refreshOnVarChange: { ri!refreshInt } ), local!component: a!refreshVariable( value: rule!MECMS_getRefComponent( selections: {"id", "value", "areaId"}, areaId: if( a!isNotNullOrEmpty(local!selectedArea), local!selectedArea, if( rule!APN_isEmpty(local!area), -1, local!area.id ) ), pagingInfo: a!pagingInfo( startIndex: 1, batchSize: - 1, sort: { a!sortInfo(field: "areaId", ascending: true), a!sortInfo(field: "value", ascending: true) } ) ).data, refreshOnVarChange: { ri!refreshInt } ), local!filteredComponents: a!refreshVariable( value: if( a!isNullOrEmpty(local!selectedComponent), local!component, index( local!component, wherecontains( tointeger(local!selectedComponent), cast( typeof({ 1, 2, 3 }), index(local!component, "id", null) ) ) ) ), refreshOnReferencedVarChange: true ), local!roles: a!refreshVariable( value: if( rule!APN_isBlank(local!selectedDepartment), null, rule!MECMS_getDepartmentRoleList( departmentId: local!selectedDepartment, activeFilter: true ) ), refreshOnVarChange: { ri!refreshInt } ), local!existingCRUD: rule!MECMS_getCRUDEntry( componentId: index(local!filteredComponents, "id", null), areaID: index(local!area, "id", null), pagingInfo: a!pagingInfo(startIndex: 1, batchSize: - 1) ).data, local!temp, { /* Filters */ a!sectionLayout( label: "", contents: { a!radioButtonField( label: "Permission Type", labelPosition: "ABOVE", choiceLabels: cons!MECMS_PERMISSION_TYPE_LABELS, choiceValues: cons!MECMS_PERMISSION_TYPE_VALUES, saveInto: { local!selectedPermission, a!save(local!selectedDepartment, null), a!save(local!selectedArea, null), a!save(local!selectedComponent, null), a!save(ri!refreshInt, ri!refreshInt + 1) }, value: local!selectedPermission, choiceLayout: "COMPACT", required: true, validations: {} ), a!columnsLayout( columns: { a!columnLayout( contents: { a!dropdownField( label: "Department", labelPosition: "ABOVE", placeholder: "--- Select a Value ---", choiceLabels: index( local!departments, "departmentName", null ), choiceValues: index(local!departments, "id", null), saveInto: { local!selectedDepartment, a!save(local!selectedArea, null), a!save(local!selectedComponent, null), a!save(ri!refreshInt, ri!refreshInt + 1) }, value: local!selectedDepartment, searchDisplay: "AUTO", required: true, validations: {} ) } ), a!columnLayout( contents: { a!dropdownField( label: "Area", labelPosition: "ABOVE", placeholder: "--- Select an Area ---", choiceLabels: local!area.value, choiceValues: local!area.id, saveInto: { local!selectedArea, a!save(local!selectedComponent, null), a!save(ri!refreshInt, ri!refreshInt + 1) }, value: local!selectedArea, searchDisplay: "AUTO", required: true, validations: {} ) } ), a!columnLayout( contents: { a!dropdownField( label: "Component", labelPosition: "ABOVE", placeholder: "--- Select a Component ---", choiceLabels: index(local!component, "value", null), choiceValues: cast(typeof({1,2}), index(local!component, "id", null)), saveInto: { local!selectedComponent }, value: local!selectedComponent, searchDisplay: "AUTO", validations: {} ) } ), a!columnLayout(contents: {}) } ) } ), /* Grid */ a!gridLayout( label: "Role Based Permissions", labelPosition: "ABOVE", headerCells: { a!gridLayoutHeaderCell(label: "Area - Component"), /*a!gridLayoutHeaderCell(label: "Test"),*/ if( rule!APN_isBlank(local!roles), {}, a!forEach( items: local!roles, expression: a!gridLayoutHeaderCell(label: fv!item.roleName) ) ) }, columnConfigs: { a!gridLayoutColumnConfig(weight: 3), /*a!gridLayoutColumnConfig(weight: "DISTRIBUTE"),*/ if( rule!APN_isBlank(local!roles), {}, a!forEach( items: local!roles, expression: a!gridLayoutColumnConfig(weight: 1) ) ) }, rows: { a!forEach( items: local!filteredComponents, expression: a!localVariables( local!currentComponent: fv!item, { a!gridRowLayout( contents: { a!richTextDisplayField( label: "", value: index( local!area.value, wherecontains(fv!item.areaId, local!area.id), null ) & " - " & fv!item.value ), a!forEach( items: local!roles, expression: a!localVariables( local!currentRole: fv!item, local!crudForCurrentRole: a!refreshVariable( value: reject( fn!isnull, a!forEach( local!existingCRUD, if( tointeger(index(fv!item, "roleId", null)) = tointeger(index(local!currentRole, "id", null)), fv!item, null ) ) ), refreshOnReferencedVarChange: true ), local!currentCRUDId: a!refreshVariable( value: reject( fn!isnull, a!forEach( local!crudForCurrentRole, if( wherecontains( tointeger( index(local!currentComponent, "id", null) ), cast(101, index(fv!item, "componentId", null)) ) = wherecontains( tointeger(index(local!currentRole, "id", null)), cast(101, index(fv!item, "roleId", null)) ), fv!item.id, null ) ) ), refreshAlways: true ), local!currentCRUD: a!refreshVariable( value: cast( typeof( 'type!{urn:com:appian:types:MECMS}MECMS_CRUDEntry'() ), reject( fn!isnull, a!forEach( local!crudForCurrentRole, if( rule!APN_isBlank(tointeger(local!currentCRUDId)), null, if( tointeger(index(fv!item, "id", null)) = tointeger(local!currentCRUDId), fv!item, null ) ) ) ) ), refreshOnReferencedVarChange: true ), local!currentCRUDSelections: a!refreshVariable( value: fn!reject( fn!isnull, { if(local!currentCRUD.create, "C", null), if(local!currentCRUD.read, "R", null), if(local!currentCRUD.update, "U", null), if(local!currentCRUD.delete, "D", null) } ), refreshOnReferencedVarChange: true ), /*a!textField(*/ /*value: local!currentCRUD*/ /*),*/ a!multipleDropdownField( label: "", placeholder: "---Select a CRUD Value ---", choiceLabels: { "Create", "Read", "Update", "Delete" }, choiceValues: { "C", "R", "U", "D" }, value: local!currentCRUDSelections, saveInto: { local!currentCRUDSelections, a!save(local!temp, local!currentCRUDId), if( rule!APN_isBlank(local!currentCRUDId), a!writeToDataStoreEntity( dataStoreEntity: cons!MECMS_CRUD_ENTRY_DSE, valueToStore: { 'type!{urn:com:appian:types:MECMS}MECMS_CRUDEntry'( deptId: tointeger(local!selectedDepartment), areaId: tointeger(local!currentComponent.areaId), roleId: tointeger(local!currentRole.id), componentId: tointeger(local!currentComponent.id), create: contains( cast(103, local!currentCRUDSelections), "C" ), read: contains( cast(103, local!currentCRUDSelections), "R" ), update: contains( cast( typeof({ "1", "2" }), local!currentCRUDSelections ), "U" ), delete: contains( cast( typeof({ "1", "2" }), local!currentCRUDSelections ), "D" ), updateBy: loggedInUser(), updateOn: now() ) }, onSuccess: { a!save( local!existingCRUD, append( local!existingCRUD, cast( typeof( { 'type!{urn:com:appian:types:MECMS}MECMS_CRUDEntry'() } ), fv!storedValues ) ) ) } ), a!writeToDataStoreEntity( dataStoreEntity: cons!MECMS_CRUD_ENTRY_DSE, valueToStore: { 'type!{urn:com:appian:types:MECMS}MECMS_CRUDEntry'( id: tointeger(local!currentCRUD.id), deptId: tointeger(local!selectedDepartment), areaId: tointeger(local!currentComponent.areaId), roleId: tointeger(local!currentRole.id), componentId: tointeger(local!currentComponent.id), create: contains( cast( typeof({ "1", "2" }), local!currentCRUDSelections ), "C" ), read: contains( cast( typeof({ "1", "2" }), local!currentCRUDSelections ), "R" ), update: contains( cast( typeof({ "1", "2" }), local!currentCRUDSelections ), "U" ), delete: contains( cast( typeof({ "1", "2" }), local!currentCRUDSelections ), "D" ), updateBy: loggedInUser(), updateOn: now() ) }, onSuccess: { a!save( local!existingCRUD, cast( typeof( { 'type!{urn:com:appian:types:MECMS}MECMS_CRUDEntry'() } ), a!update( local!existingCRUD, index(local!currentCRUDId, 1, null), fv!storedValues ) ) ) } ) ) } ) ) ) } ) } ) ) }, selectionSaveInto: {}, validations: {}, shadeAlternateRows: true ), a!columnsLayout( columns: { a!columnLayout( contents: { a!buttonArrayLayout( buttons: { a!buttonWidget( label: "BACK", style: "DESTRUCTIVE", saveInto: { a!save(ri!manageCRUD, not(ri!manageCRUD)), a!save( ri!showParentCancel, not(ri!showParentCancel) ) } ) }, align: "START" ) } ) } ) } )
I am getting the above error with reject function so please let me know what causing this error .
Discussion posts and replies are publicly visible
It could be that the line
tointeger(index(fv!item, "id", null)) = tointeger(local!currentCRUDId),
returns a list if one of the operands is a list. Then your foreach returns a list with some items be another list. Then reject() fails.
A few hints:
You can reference a type directly typing: 'type!{urn:com:appian:types:MECMS}MECMS_CRUDEntry'. You don't have to first create a data structure by calling the constructor, just to then extract the type from it.
Then, the check for "local!currentCRUDId" does not depend on the items in the list and is either true or false for all items. Try to wrap the whole value expression into an if checking for "local!currentCRUDId".
Stefan Helzle Thank you for the reply. I have fixed the issue by wrapping a!flatten function around for each function and it seems to be working