Skip to main content
November 28, 2022
Solved

Updating DB in a new row instead of existing row

  • November 28, 2022
  • 3 replies
  • 0 views

I have form where I need to update the DB for an already existing row with the Date details. But when I clcik on submit it is creating a new row. Please help.

a!formLayout(
  label: "Employee Leave Application ",
  contents: {
    a!sectionLayout(
      label: "",
      contents: rule!ELT_EmployeeDetails_Summary(
        rule!ELT_GetEmployeeDetailsByUser(loggedInUser())
      )
    ),
    a!columnsLayout(
      columns: {
        a!columnLayout(
          contents: {
            a!dateField(
              label: "Start Date",
              labelPosition: "ABOVE",
              value: ri!EmpLeave.leaveStartDate,
              saveInto: ri!EmpLeave.leaveStartDate,
              validations: {}
            )
          }
        ),
        a!columnLayout(
          contents: {
            a!dateField(
              label: "End Date",
              labelPosition: "ABOVE",
              value: ri!EmpLeave.leaveEndDate,
              saveInto: ri!EmpLeave.leaveEndDate,
              validations: {}
            )
          }
        )
      }
    ),
    a!textField(
      label: "Reason for Leave",
      labelPosition: "ABOVE",
      value: ri!EmpLeave.leaveReason,
      saveInto: ri!EmpLeave.leaveReason,
      refreshAfter: "UNFOCUS",
      validations: {}
    )
  },
  buttons: a!buttonLayout(
    primaryButtons: {
      a!buttonWidget(
        label: "Submit",
        saveInto: {
          a!writeToDataStoreEntity(dataStoreEntity: cons!ELT_EMPLOYEE_DETAILS,valueToStore: ri!EmpLeave),
          a!save(ri!EmpLeave.updatedBy, loggedInUser()),
          a!save(ri!EmpLeave.updatedDate, now())
        },
        submit: true,
        style: "PRIMARY",
        loadingIndicator: true
      )
    },
    secondaryButtons: {
      a!buttonWidget(
        label: "Cancel",
        value: true,
        saveInto: ri!Cancel,
        submit: true,
        style: "NORMAL",
        validate: false
      )
    }
  )
)
.

    Best answer by harshas2775

    In order to perform the update operation,the primary key- employeeId- should not be null. 

    Pass in the context for EmpLeave cdt when the form loads. This way when the form loads EmpLeave will not be empty but will be populated with the data in all fields including the Id one. That will resolve the issue. By passing the data for rule input, you can use the same CDT to populate Employee Details section as well instead of calling the query rule to return the employeeDetails again. 

    So from wherever you are calling this interface pass in the input as rule!ELT_getEmployeeDetailsByUser(loggedInUser()) against EmpLeave rule input.

    3 replies

    harshas2775
    Brainy
    November 28, 2022

    In order to perform the update operation,the primary key- employeeId- should not be null. 

    Pass in the context for EmpLeave cdt when the form loads. This way when the form loads EmpLeave will not be empty but will be populated with the data in all fields including the Id one. That will resolve the issue. By passing the data for rule input, you can use the same CDT to populate Employee Details section as well instead of calling the query rule to return the employeeDetails again. 

    So from wherever you are calling this interface pass in the input as rule!ELT_getEmployeeDetailsByUser(loggedInUser()) against EmpLeave rule input.

    November 28, 2022

    Thanks Harsha, It worked.

    Now Im able to update the first row in DB. Could you please tell how to update the remaining rows in DB with the same input.

    November 28, 2022

    you have to pass the primary key of each row to update the data in the table.