Showing excel data in editable grid

Certified Associate Developer

I am trying to show Student Data in editable grid through excel with marks in subjects. there is a field with total marks which is depend on marks from other fields. Problem is i am able to when i change marks of any subject changes get reflect in the MarksObtained field which is the sum of marks of all subjects but when i submit it does not store the changed data in Marksobtained field. it stores the original data which is in excel file.

a!localVariables(
 
a!formLayout(
  label: "Student Details",
  contents: {
    a!sectionLayout(
      contents: {
        a!gridLayout(
          label: "Editable Grid",
          labelPosition: "ABOVE",
          headerCells: {
            a!gridLayoutHeaderCell(label: "RollNumber"),
            a!gridLayoutHeaderCell(label: "FullName"),
            a!gridLayoutHeaderCell(label: "Hindi"),
            a!gridLayoutHeaderCell(label: "English"),
            a!gridLayoutHeaderCell(label: "Maths"),
            a!gridLayoutHeaderCell(label: "Physics"),
            a!gridLayoutHeaderCell(label: "Chemistry"),
            a!gridLayoutHeaderCell(label: "ObtainedMarks"),
            /*a!gridLayoutHeaderCell(label: "TotalMarks"),*/
            a!gridLayoutHeaderCell(label: "Percentage"),
            a!gridLayoutHeaderCell(label: "Result"),
          },
          columnConfigs: {
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            /*a!gridLayoutColumnConfig(width: "DISTRIBUTE"),*/
          },
          rows: {
            a!forEach(
              items: ri!studentData,
              expression: a!gridRowLayout(
                contents: {
                  a!integerField(
                    value: fv!item.RollNumber,
                    saveInto: fv!item.RollNumber,
                    disabled: true
                  ),
                  a!textField(
                    value: fv!item.FullName,
                    saveinto: fv!item.FullName
                  ),
                  a!integerField(
                    value: fv!item.Hindi,
                    saveInto: fv!item.Hindi,
                    validations: {
                      if(
                        fv!item.Hindi>100,
                        "Marks should be between 0 and 100",
                        if(
                          fv!item.Hindi< 0,
                          "Marks should be between 0 and 100",
                          "")
                    )
                    }
                  ),
                  a!integerField(
                    value: fv!item.English,
                    saveInto: fv!item.English,
                    validations: {
                      if(
                        fv!item.English>100,
                        "Marks should be between 0 and 100",
                        if(
                          fv!item.English< 0,
                          "Marks should be between 0 and 100",
                          "")
                      )
                    }
                  ),
                  a!integerField(
                    value: fv!item.Maths,
                    saveInto: fv!item.Maths,
                    validations: {
                      if(
                        fv!item.Maths>100,
                        "Marks should be between 0 and 100",
                        if(
                          fv!item.Maths< 0,
                          "Marks should be between 0 and 100",
                          "")
                      )
                    }
                  ),
                  a!integerField(
                    value: fv!item.Physics,
                    saveInto: fv!item.Physics,validations: {
                      if(
                        fv!item.Physics>100,
                        "Marks should be between 0 and 100",
                        if(
                          fv!item.Physics< 0,
                          "Marks should be between 0 and 100",
                          "")
                      )
                    }
                  ),
                  a!integerField(
                    value: fv!item.Chemistry,
                    saveInto: fv!item.Chemistry,
                    validations: {
                      if(
                        fv!item.Chemistry>100,
                        "Marks should be between 0 and 100",
                        if(
                          fv!item.Chemistry< 0,
                          "Marks should be between 0 and 100",
                          "")
                      )
                    }
                  ),
                  a!integerField(
                    value: fv!item.Hindi+fv!item.English+fv!item.Maths+fv!item.Chemistry+fv!item.Physics,
                    saveInto:fv!item.MarksObtained,
                    disabled:true
                  ),
                  /*a!integerField(*/
                    /*value: fv!item.TotalMarks,*/
                    /*saveInto: fv!item.TotalMarks*/
                  /*),*/
                  a!floatingPointField(
                    value: (fv!item.Hindi+fv!item.English+fv!item.Maths+fv!item.Chemistry+fv!item.Physics)/fv!item.TotalMarks*100 ,
                    saveInto: fv!item.Percentage,
                    disabled: true
                  ),
                  a!textField(
                    value: If(
                      (fv!item.Hindi+fv!item.English+fv!item.Maths+fv!item.Chemistry+fv!item.Physics)/fv!item.TotalMarks*100 > 33,
                      "Pass",
                      "Fail"
                    ),
                    saveinto: fv!item.Result,
                    disabled: true
                  ),
                }
              )
            )
          },
          selectionSaveInto: {},
          addRowLink: a!dynamicLink(
            label: "Add Student",
            saveInto: {
            }
          ),
          validations: {},
          shadeAlternateRows: true
        )
      }
    )
  },
  buttons: a!buttonLayout(
    primaryButtons: {
      a!buttonWidget(
        label: "Submit",
        saveInto: {
         
        },
        submit: true,
        style: "PRIMARY"
      )
    },
    secondaryButtons: {
      a!buttonWidget(
        label: "Cancel",
        value: true,
        saveInto: ri!cancel,
        submit: true,
        style: "NORMAL",
        validate: false
      )
    }
  )
)
)

  Discussion posts and replies are publicly visible

Parents
  • You need to understand one thing that saveInto expressions are only evaluated on user interaction.

    changes get reflect in the MarksObtained field

    This will only take effect in the display value of the component and not in the actual field where you are trying to save the value, as these components are disabled and there is no user interaction to save the value in rule inputs.

    It is clear that we need user interaction to save the values in MarksObtained, Percentage... fields, but the question is where will the user interact?? We have displayed the updated values in the grid that user wants to see but for storing them in variables we will utilize button widget's saveInto parameter.

    And inside that you will write something like: (Sample code)

    saveInto: a!forEach(
       ri!studentData,
       {
         a!save(
           fv!item.MarksObtained,
           sum(fv!item.Physics, fv!item.Chemistry)
         ),
         a!save(
           fv!item.Percentage,
           (fv!item.MarksObtained/fv!item.TotalMarks)*100
         )
       }
     )

Reply Children
No Data