Hi,
I have a editable grid where in one field has single select dropdown (i.e Status),
a!localVariables( local!data: rule!Data_Rule( serialNumber: null, pageBatchSize: -1 ), local!statusToUpdate, { a!gridLayout( label: "Editable Grid", labelPosition: "COLLAPSED", headerCells: { a!gridLayoutHeaderCell(label: "Serial Number"), a!gridLayoutHeaderCell(label: "Status") }, columnConfigs: {}, rows: { a!forEach( items: local!data, expression: { a!gridRowLayout( contents: { a!textField( label: "Serial Number", value: fv!item.serialNumber ), a!dropdownField( label: "Status", labelPosition: "ABOVE", choiceLabels: rule!RWM_Status_Matrix_Rule(currentStatus:fv!item.currentStatus), choiceValues: rule!RWM_Status_Matrix_Rule(currentStatus:fv!item.currentStatus), value:if(not(isnull(local!statusToUpdate)),local!statusToUpdate,fv!item.currentStatus), saveInto: { a!save(local!statusToUpdate,save!value), a!save(ri!dataList, save!value) }, searchDisplay: "ON", required:true, validations: { } ) } ) } ) }, selectionSaveInto: {}, validations: {}, shadeAlternateRows: true ), a!buttonArrayLayout( buttons: { a!buttonWidget( label: "Save", style: "PRIMARY", saveInto: { /*Code to write updated value in DB*/ } ) }, align: "END" ) } )
and the value in the dropdown is populated from a expression rule file (below) which has different value for every status selected.
a!localVariables( local!pendingStatusMatrix:{"Pending","Started","Cancelled"}, local!startedStatusMatrix:{"Started","Suspended","Completed"}, local!suspendedStatusMatrix:{"Suspended","Resumed","Completed"}, local!resumedStatusMatrix:{"Resumed","Suspended","Completed"}, local!completeStatusMatrix:{"Completed"}, local!cancelledStatusMatrix:{"Cancelled"}, { if(ri!currentStatus="Pending",local!pendingStatusMatrix,{}), if(ri!currentStatus="Started",local!startedStatusMatrix,{}), if(ri!currentStatus="Suspended",local!suspendedStatusMatrix,{}), if(ri!currentStatus="Resumed",local!resumedStatusMatrix,{}), if(ri!currentStatus="Completed",local!completeStatusMatrix,{}), if(ri!currentStatus="Cancelled",local!cancelledStatusMatrix,{}) } )
There is a button (SAVE) outside of editable grid which is pressed whenever any status is changed to update it in DB.
Now, what I am trying to achieve is whenever I press on SAVE button the value should be updated in DB (its working fine for me) and single select dropdown (i.e Status) should be updated with new value options based in current status selection.
Please hep me with it.
Discussion posts and replies are publicly visible
You'll need to make more extensive use of the neat new capabilities available in the new a!localVariables() toolset, specifically a!refreshVariable settings. The following represents my normal technique for doing this sort of thing:
a!localVariables( local!refreshCounter: 0, local!data: a!refreshVariable( value: rule!Data_Rule( serialNumber: null, pageBatchSize: -1 ), refreshOnVarChange: { local!refreshCounter } ), local!statusToUpdate, { a!gridLayout( label: "Editable Grid", labelPosition: "COLLAPSED", headerCells: { a!gridLayoutHeaderCell(label: "Serial Number"), a!gridLayoutHeaderCell(label: "Status") }, columnConfigs: {}, rows: { a!forEach( items: local!data, expression: { a!gridRowLayout( contents: { a!textField( label: "Serial Number", value: fv!item.serialNumber ), a!dropdownField( label: "Status", labelPosition: "ABOVE", choiceLabels: rule!RWM_Status_Matrix_Rule(currentStatus:fv!item.currentStatus), choiceValues: rule!RWM_Status_Matrix_Rule(currentStatus:fv!item.currentStatus), value:if(not(isnull(local!statusToUpdate)),local!statusToUpdate,fv!item.currentStatus), saveInto: { a!save(local!statusToUpdate,save!value), a!save(ri!dataList, save!value) }, searchDisplay: "ON", required:true, validations: { } ) } ) } ) }, selectionSaveInto: {}, validations: {}, shadeAlternateRows: true ), a!buttonArrayLayout( buttons: { a!buttonWidget( label: "Save", style: "PRIMARY", saveInto: { /*Code to write updated value in DB*/ a!writeToDataStoreEntity( dataStoreEntity: cons!ASDF_MY_DSE, valueToStore: {/* value */}, onSuccess: { a!save( local!refreshCounter, local!refreshCounter + 1 ) } ) } ) }, align: "END" ) } )
This does not seem to work, status dropdown is not refreshing, in fact the variable "local!refreshCounter" counter in increasing but the "local!data" is not refreshing.
What does the rule rule!Data_Rule() contain?
It has query to fetch data (below)
a!queryEntity( entity: cons!DATA, query: a!query( logicalexpression: a!queryLogicalExpression( operator: "AND", logicalExpressions: { a!queryLogicalExpression( ignoreFiltersWithEmptyValues: true, operator: "OR", filters: { a!forEach( ri!namedsiteid, a!queryFilter( field: "namedsiteid", operator: "includes", value: fv!item ) ) } ) }, filters: { a!queryFilter( field: "serialnumber", operator: "=", value: ri!serialnumber ) }, ignoreFiltersWithEmptyValues: true ), selection: a!querySelection( columns: { a!forEach( { "serialnumber", "status" }, a!queryColumn(field: fv!item) ) } ), pagingInfo: a!pagingInfo( startIndex: 1, batchSize: ri!pageBatchSize, sort: { a!sortInfo( field: "serialnumber", ascending: true ), a!sortInfo(field: "status", ascending: false) } ) ), fetchTotalCount: false ).data
That looks ok. What I was fishing for was whether it uses local variables of the wrong configuration (load() or a!refreshVariable() with the wrong settings), but guess not.
Can you post the code just for the saveInto section you're trying, including whatever you're calling to update the data and including the refresh counter increment? My suspicion now is that the refresh is firing before the update is completed, but currently there's not enough information posted to tell for sure.
Please have a look below
a!localVariables( local!refreshCounter: 0, local!data: a!refreshVariable( value: rule!Data_Rule( serialNumber: null, pageBatchSize: -1 ), refreshOnVarChange: local!refreshCounter ), { a!gridLayout( label: "Editable Grid", labelPosition: "COLLAPSED", headerCells: { a!gridLayoutHeaderCell(label: "Serial Number"), a!gridLayoutHeaderCell(label: "Status") }, columnConfigs: {}, rows: { a!forEach( items: local!data, expression: a!localVariables( local!statusToUpdate, a!gridRowLayout( contents: { a!textField( label: "Serial Number", value: fv!item.serialNumber ), a!dropdownField( label: "Status", labelPosition: "ABOVE", choiceLabels: rule!RWM_Status_Matrix_Rule(currentStatus:fv!item.currentStatus), choiceValues: rule!RWM_Status_Matrix_Rule(currentStatus:fv!item.currentStatus), value:if(not(isnull(local!statusToUpdate)),local!statusToUpdate,fv!item.currentStatus), saveInto: { a!save(local!statusToUpdate,save!value), a!save(ri!dataList, save!value) }, searchDisplay: "ON", required:true, validations: { } ) } ) ) ) }, selectionSaveInto: {}, validations: {}, shadeAlternateRows: true ), a!buttonArrayLayout( buttons: { a!buttonWidget( label: "Save", style: "PRIMARY", saveInto: { a!startProcess( processModel: cons!SAMPLE, processParameters: { /*Parameters to call Process Model which will update DB records*/ }, onSuccess: { a!save(local!refreshCounter,local!refreshCounter+1) }, onError:{ /*Text error message*/ } ) } ) }, align: "END" ) } )
Oh - I don't think you mentioned you're using a!startProcess as opposed to a!writeToDataStoreEntity. This is fine, though. Can you check to ensure you have activity chaining enabled in the process model from the start node and all the way through to your WTDS node at least? This is usually the solution to this sort of issue. If chaining breaks early (or doesn't exist) the "onSuccess" save(s) will happen too early (or immediately).
Worked Thanks!
Great, thanks for confirming/verifying