------------Main Rule--------------- load( local!selectionValue, local!purchaseRequest:{{"id":1,"summary":"PR1"},{"id":2,"summary":"PR2"}}, local!PurchaseRequestItem: {{"id":1,"summary":"Item 1","qty":2,"unitPrice":5,"purchaseReqId":1}, {"id":2,"summary":"Item 2","qty":3,"unitPrice":50,"purchaseReqId":1}, {"id":3,"summary":"Item 3","qty":1,"unitPrice":100,"purchaseReqId":2}, {"id":4,"summary":"Item 4","qty":5,"unitPrice":30,"purchaseReqId":2}, {"id":5,"summary":"Item 5","qty":10,"unitPrice":20,"purchaseReqId":2} }, { a!gridLayout( headerCells: { a!gridLayoutHeaderCell(label: "Summary"), a!gridLayoutHeaderCell(label: "Qty", align: "RIGHT"), a!gridLayoutHeaderCell(label: "Unit Price", align: "RIGHT"), a!gridLayoutHeaderCell(label: "Total Price", align: "RIGHT") }, columnConfigs: { a!gridLayoutColumnConfig("DISTRIBUTE"), a!gridLayoutColumnConfig("NARROW"), a!gridLayoutColumnConfig("DISTRIBUTE"), a!gridLayoutColumnConfig("DISTRIBUTE") }, rows: /*cast( typeof({a!gridRowLayout(contents: {})}),*/ a!applyComponents( function: rule!Sample_treeGridRows(purchareRequests:local!purchaseRequest,items: local!PurchaseRequestItem, reqIndex: _), array: enumerate(length(local!purchaseRequest))+1 /*function:rule!Sample_treeGridItemRow(items:local!PurchaseRequestItem,index:_), array: enumerate(length(local!PurchaseRequestItem))+1*/ ) /*)*/, selectable :true(), selectionValue:local!selectionValue, selectionSaveInto :local!selectionValue ), a!textField( label:"test data", value:local!selectionValue &"----"& apply(fn!trim,index(local!PurchaseRequestItem,"id",{})) &"----"& displayvalue(local!selectionValue,apply(fn!trim,index(local!PurchaseRequestItem,"id",{})),local!PurchaseRequestItem,{}) ) } ) -------------Rule Sample_treeGridRows----------------- load( local!expanded:false, with( local!itemsByPurchaseReq:index(ri!items,wherecontains(index(ri!purchareRequests[ri!reqIndex],"id",{}), index(ri!items,"purchaseReqId",{}) )), local!totalPrice: sum(apply(fn!product, merge(local!itemsByPurchaseReq.qty, local!itemsByPurchaseReq.unitPrice))), { a!gridRowLayout( selectionDisabled:true(), id:ri!reqIndex, contents: { a!richTextDisplayField( label: "Summary " & ri!reqIndex, value: { a!richTextItem( text: if(local!expanded, "-", "+")&" "&ri!purchareRequests[ri!reqIndex].summary, link: a!dynamicLink( value: not(local!expanded), saveInto: local!expanded ) ) } ), a!textField( label: "Qty " & ri!reqIndex, readOnly: true ), a!textField( label: "Unit Price " & ri!reqIndex, readOnly: true ), a!textField( label: "Total Price " & ri!reqIndex, value: dollar(local!totalPrice), readOnly: true, align: "RIGHT" ) } ), if(local!expanded, a!applyComponents( function: rule!Sample_treeGridItemRow(items: local!itemsByPurchaseReq, index: _), array: enumerate(length(local!itemsByPurchaseReq))+1 ),{} ) } ) ) -------------Rule Sample_treeGridItemRow----------------- a!gridRowLayout( id:tointeger(ri!items[ri!index].id), contents:{ a!richTextDisplayField( label: "Item Summary " & ri!index, value: a!richTextBulletedList( items: ri!items[ri!index].summary ) ), a!integerfield( label: "Item Qty " & ri!index, value:ri!items[ri!index].qty, readOnly:true(), align: "RIGHT" ), a!textfield( label: "Unit Price " & ri!index, value:if(rule!APN_isBlank(ri!items[ri!index].unitPrice),"",dollar(ri!items[ri!index].unitPrice)), readOnly:true(), align: "RIGHT" ), a!textField( label: "Item Total Price " & ri!index, value: if(rule!APN_isBlank(ri!items[ri!index].qty),"",dollar(tointeger(ri!items[ri!index].qty) * todecimal(ri!items[ri!index].unitPrice))), readOnly: true(), align: "RIGHT" ) } )