Hi , I am working on requirement when creating a request for a user some plan will be available they can select any of the plan.Its ready only. It will be write to request plan table . Later in another task they will have option to select other plans belongs to them and they want to edit the plan name as well and they want to add new plans for the request alone and for the task related to it. Now this plan are populated from reference table we shouldn't alter that. So I tried to create the new plans from ref of type above mentioned request plan table. And I created a editable grid to populated the plan name to have option of edit . But I m struct saving the local data to rule input .
This is my expression to create request plan from ref table
local!gridDataforPlan: a!forEach( items: local!existingClientPlans, expression: if( contains( tointeger( index( local!vetRequestPlans, 'recordType! Request Plans.fields.planId', {} )), fv!item['recordType!ref PLAN.fields.planId'] ), a!update( data: local!vetRequestPlans, index: wherecontains( fv!item['recordType!WMS PLAN.fields.planId'], tointeger( index( local!vetRequestPlans, 'recordType!Request Plans.fields.planId', {} ) ) ), value: 'recordType! Request Plans'( 'recordType! Request Plans.fields.planId': fv!item['recordType!planId'], 'recordType!Request Plans.fields.citPlan': fv!item['recordType!planName'] ) ), 'recordType!VET Request Plans'( 'recordType! Request Plans.fields.planId': fv!item['recordType!REF PLan .fields.planId'], 'recordType! Request Plans.fields.citPlan': fv!item['recordType!REF PLAN.fields.planName'] ) ) ) ,
This is my grid layout
a!gridLayout( label: "", labelPosition: "COLLAPSED", headerCells: { a!gridLayoutHeaderCell(label: "Plan name(s) for Rider A"), a!gridLayoutHeaderCell(label: "") }, columnConfigs: { a!gridLayoutColumnConfig(width: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "ICON"), }, rows: a!forEach( items: local!gridDataforPlan, expression: a!gridRowLayout( id: fv!index, contents: { a!textField( value: local!gridDataforPlan['recordType!Request Plans.fields.citPlan'][fv!index], saveInto: local!gridDataforPlan['recordType! Request Plans.fields.citPlan'][fv!index] ), a!richTextDisplayField( value: { a!richTextImage( image: a!documentImage( document: a!iconIndicator(icon: "REMOVE"), altText: "Remove", caption: "Remove", link: a!dynamicLink( value: local!gridDataforPlan[fv!index], saveInto: { a!save( local!gridDataforPlan, remove(local!gridDataforPlan, fv!index) ) } ) ) ) }, showWhen: not(ri!readOnly), align: "CENTER" ) } ) ), showWhen: not(ri!readOnly), selectable: true, selectionValue: local!selectedPlans, selectionSaveInto:{a!save(local!selectedPlans,a!flatten(save!value))}, addRowLink: a!dynamicLink( label: "Add Plan", value: 'recordType! Request Plans'( 'recordType! Request Plans.fields.requestId': ri!vetRequestMaster['recordType!Request Master.fields.requestId'], 'recordType! Request Plans.fields.citPlan': null(), 'recordType! Request Plans.fields.isActive': true, 'recordType! Request Plans.fields.createdBy': loggedInUser(), 'recordType! Request Plans.fieldscreatedOn': now(), 'recordType! Request Plans.fields.updatedBy': loggedInUser(), 'recordType! Request Plans.fields.updatedOn': now() ), saveInto: { a!save( target: local!gridDataforPlan, value: append(local!gridDataforPlan, save!value) ), }, showWhen: not(ri!readOnly) ), ),
This is the save button when after selecting the row I want to save them into rule input
a!buttonLayout( primaryButtons: { a!buttonWidget( label: "Save", saveInto: { a!save( target: local!RequestPlans, a!forEach( items: local!selectedPlans, expression: index(local!gridDataforPlan, fv!item, {}) ) ) ) a!save(ri!requestPlan, local!requestPlan) } ) } )
For now when I select a plan and add a new plan and give save those rows are again getting added to grid and I want to do one more thing here if the rule input request plan have any of the selected local plan value I want to update that with plan name .
Discussion posts and replies are publicly visible
I found your save logic is incorrectly structured.Selected plans are being re-added to the grid instead of being saved to the rule input.No logic to update existing plans when plan names are edited.Try this below implementation Note : As i can't configure record in code properly so you have to check code properly.Save Button Code :-
a!buttonWidget( label: "Save", saveInto: { a!save( target: ri!requestPlan, value: a!forEach( items: local!selectedPlans, expression: a!localVariables( local!currentPlan: index(local!gridDataforPlan, fv!item, {}), local!planId: index( local!currentPlan, 'recordType!Request Plans.fields.planId', null() ), local!existingIndex: wherecontains( local!planId, index( ri!requestPlan, 'recordType!Request Plans.fields.planId', {} ) ), if( or( isnull(local!existingIndex), length(local!existingIndex) = 0 ), /* Add new plan / append(ri!requestPlan, local!currentPlan), / Update existing plan / a!update( data: ri!requestPlan, index: local!existingIndex[1], value: local!currentPlan ) ) ) ) ), / Clear selections after save */ a!save(local!selectedPlans, {}) }, style: "PRIMARY" )
a!textField( value: index( local!gridDataforPlan[fv!index], 'recordType!Request Plans.fields.citPlan', "" ), saveInto: a!save( local!gridDataforPlan[fv!index]['recordType!Request Plans.fields.citPlan'], save!value ) )