Error in writing data to database tables

Hi readers,

I have a code for an interface which is working one way but it is not working in another way would like to know the reason 

attaching the initial code and final code

Initial code: Issue facing in lines 71 to 101 

a!localVariables(
  local!QueryVMId: rule!IV_QueryVMDetails().VM_ID,
  local!QueryVMName: rule!IV_QueryVMDetails().VM_Host_Name,
  local!Temp: null(),
  a!formLayout(
    label: "Add New Server/Node",
    contents: {
      a!cardLayout(
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    label: "VM_Name",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: local!QueryVMName,
                    choiceValues: local!QueryVMName,
                    value: local!Temp,
                    saveInto: local!Temp,
                    searchDisplay: "AUTO",
                    showWhen: true,
                    required: true,
                    validations: {}
                  ),
                  a!textField(
                    label: "Server/Node Name",
                    labelPosition: "ABOVE",
                    value: ri!record.Server_Node_Name,
                    saveInto: ri!record.Server_Node_Name,
                    characterLimit: 255,
                    showCharacterCount: false,
                    required: true
                  ),
                  a!textField(
                    label: "Server/Node IP",
                    labelPosition: "ABOVE",
                    value: ri!record.Server_Node_IP,
                    saveInto: ri!record.Server_Node_IP,
                    characterLimit: 40,
                    showCharacterCount: false,
                    required: true
                  ),
                  a!dropdownField(
                    label: "Memory (In GB)",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!Internal_Memory_RAM,
                    choiceValues: cons!Internal_Memory_RAM,
                    value: ri!record.Memory,
                    saveInto: ri!record.Memory,
                    searchDisplay: "AUTO",
                    validations: {}
                  ),
                  a!dropdownField(
                    label: "C. P. U Cores",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!CPU_Cores,
                    choiceValues: cons!CPU_Cores,
                    value: ri!record.CPU_Cores,
                    saveInto: ri!record.CPU_Cores,
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!integerField(
                    label: "VM_ID: ",
                    labelPosition: "JUSTIFIED",
                    value: {
                        a!queryEntity(
                          entity: cons!IV_VM_DSE,
                          query: a!query(
                            selection: a!querySelection(
                              columns: { a!queryColumn(field: "VM_ID") }
                            ),
                            logicalExpression: a!queryLogicalExpression(
                              operator: "AND",
                              filters: {
                                a!queryFilter(
                                  field: "VM_Host_Name",
                                  operator: "=",
                                  value: local!Temp
                                )
                              },
                              ignoreFiltersWithEmptyValues: true
                            ),
                            pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 50)
                          ),
                          fetchTotalCount: false
                        ).data.VM_ID
                    },
                    saveInto: ri!record.VM_ID_FK,
                    showWhen: a!isNotNullOrEmpty(local!Temp),
                    required: false,
                    readOnly: true
                  ),
                  a!textField(
                    label: "SQL Server Instance Name",
                    labelPosition: "ABOVE",
                    value: ri!record.SQL_Server_Instance_Name,
                    saveInto: ri!record.SQL_Server_Instance_Name,
                    characterLimit: 255,
                    showCharacterCount: false,
                    required: false
                  ),
                  a!textField(
                    label: "SQL Server Version",
                    labelPosition: "ABOVE",
                    value: ri!record.SQL_Server_Version,
                    saveInto: ri!record.SQL_Server_Version,
                    characterLimit: 255,
                    showCharacterCount: false,
                    required: false
                  ),
                  a!dropdownField(
                    label: "DR - Availability",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!DR_Availability,
                    choiceValues: cons!DR_Availability,
                    value: ri!record.DR_Availability,
                    saveInto: ri!record.DR_Availability,
                    searchDisplay: "AUTO",
                    validations: {}
                  ),
                  a!integerField(
                    label: "SQL Server Port",
                    labelPosition: "ABOVE",
                    value: ri!record.SQL_Port,
                    saveInto: ri!record.SQL_Port,
                    required: false
                  ),
                  a!textField(
                    label: "Database Count/Name",
                    labelPosition: "ABOVE",
                    value: ri!record.Db_Count_Name,
                    saveInto: ri!record.Db_Count_Name,
                    characterLimit: 150,
                    required: false
                  ),
                  a!dropdownField(
                    label: "Backup PIS",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!Backup_Process_Improvement_Status,
                    choiceValues: cons!Backup_Process_Improvement_Status,
                    value: ri!record.Backup_PIS,
                    saveInto: ri!record.Backup_PIS,
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                }
              )
            },
            marginAbove: "NONE",
            marginBelow: "STANDARD"
          )
        },
        height: "AUTO",
        style: "NONE",
        shape: "ROUNDED",
        marginAbove: "NONE",
        marginBelow: "LESS",
        showShadow: true,
        decorativeBarPosition: "TOP",
        decorativeBarColor: "#000000"
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Add",
          icon: "plus",
          submit: true,
          style: "PRIMARY",
          validate: true
        )
      }
    )
  )
)

Final Code which worked out

a!localVariables(
  local!QueryVMId: rule!IV_QueryVMDetails().VM_ID,
  local!QueryVMName: rule!IV_QueryVMDetails().VM_Host_Name,
  local!Temp: null(),
  a!formLayout(
    label: "Add New Server/Node",
    contents: {
      a!cardLayout(
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    label: "VM_Name",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: local!QueryVMName,
                    choiceValues: local!QueryVMName,
                    value: local!Temp,
                    saveInto: local!Temp,
                    searchDisplay: "AUTO",
                    showWhen: true,
                    required: true,
                    validations: {}
                  ),
                  a!textField(
                    label: "Server/Node Name",
                    labelPosition: "ABOVE",
                    value: ri!record.Server_Node_Name,
                    saveInto: ri!record.Server_Node_Name,
                    characterLimit: 255,
                    showCharacterCount: false,
                    required: true
                  ),
                  a!textField(
                    label: "Server/Node IP",
                    labelPosition: "ABOVE",
                    value: ri!record.Server_Node_IP,
                    saveInto: ri!record.Server_Node_IP,
                    characterLimit: 40,
                    showCharacterCount: false,
                    required: true
                  ),
                  a!dropdownField(
                    label: "Memory (In GB)",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!Internal_Memory_RAM,
                    choiceValues: cons!Internal_Memory_RAM,
                    value: ri!record.Memory,
                    saveInto: ri!record.Memory,
                    searchDisplay: "AUTO",
                    validations: {}
                  ),
                  a!dropdownField(
                    label: "C. P. U Cores",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!CPU_Cores,
                    choiceValues: cons!CPU_Cores,
                    value: ri!record.CPU_Cores,
                    saveInto: ri!record.CPU_Cores,
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!textField(
                    label: "SQL Server Instance Name",
                    labelPosition: "ABOVE",
                    value: ri!record.SQL_Server_Instance_Name,
                    saveInto: ri!record.SQL_Server_Instance_Name,
                    characterLimit: 255,
                    showCharacterCount: false,
                    required: false
                  ),
                  a!textField(
                    label: "SQL Server Version",
                    labelPosition: "ABOVE",
                    value: ri!record.SQL_Server_Version,
                    saveInto: ri!record.SQL_Server_Version,
                    characterLimit: 255,
                    showCharacterCount: false,
                    required: false
                  ),
                  a!dropdownField(
                    label: "DR - Availability",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!DR_Availability,
                    choiceValues: cons!DR_Availability,
                    value: ri!record.DR_Availability,
                    saveInto: ri!record.DR_Availability,
                    searchDisplay: "AUTO",
                    validations: {}
                  ),
                  a!integerField(
                    label: "SQL Server Port",
                    labelPosition: "ABOVE",
                    value: ri!record.SQL_Port,
                    saveInto: ri!record.SQL_Port,
                    required: false
                  ),
                  a!textField(
                    label: "Database Count/Name",
                    labelPosition: "ABOVE",
                    value: ri!record.Db_Count_Name,
                    saveInto: ri!record.Db_Count_Name,
                    characterLimit: 150,
                    required: false
                  ),
                  a!dropdownField(
                    label: "Backup PIS",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!Backup_Process_Improvement_Status,
                    choiceValues: cons!Backup_Process_Improvement_Status,
                    value: ri!record.Backup_PIS,
                    saveInto: ri!record.Backup_PIS,
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                }
              )
            },
            marginAbove: "NONE",
            marginBelow: "STANDARD"
          )
        },
        height: "AUTO",
        style: "NONE",
        shape: "ROUNDED",
        marginAbove: "NONE",
        marginBelow: "LESS",
        showShadow: true,
        decorativeBarPosition: "TOP",
        decorativeBarColor: "#000000"
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Add",
          icon: "plus",
          submit: true,
          saveInto: a!save(
            ri!record.VM_ID_FK,
            a!queryEntity(
              entity: cons!IV_VM_DSE,
              query: a!query(
                selection: a!querySelection(columns: { a!queryColumn(field: "VM_ID") }),
                logicalExpression: a!queryLogicalExpression(
                  operator: "AND",
                  filters: {
                    a!queryFilter(
                      field: "VM_Host_Name",
                      operator: "=",
                      value: local!Temp
                    )
                  },
                  ignoreFiltersWithEmptyValues: true
                ),
                pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 50)
              ),
              fetchTotalCount: false
            ).data.VM_ID
          ),
          style: "PRIMARY",
          validate: true
        )
      }
    )
  )
)

Things, I have changed are from initial and Final code are; in initial code in line 71 there is a integer field VM_ID which has a value label when used this code the value which displayed was okay but when submit button was pressed and process was initiated the values is going as null,

So i have taken the same code present against the value label and wrote saveInto label at buttons field  with the help of a!save i.e, in line 159; When this was done the value was written to table perfectly.

Both were almost same would like to know the reason y this happened.

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Senior Developer

    Hi , In your first code for the integer field, you are updating its value using query entity based on local variable "local!temp". You are not interacting with this field by yourself , hence saveInto here is not working. saveInto only works when you interact with the field manually, means if you make any changes for the field. In your second code, you are saving "VM_ID_FK"  in submit button's saveInto parameter and this is clicked by the user, so everything under saveInto will be saved, hence you are able to save the value. One more thing i would recommend is not to use query entity in value parameter of the field, you can configure this in a local variable with refresh variable parameter.

Reply
  • +1
    Certified Senior Developer

    Hi , In your first code for the integer field, you are updating its value using query entity based on local variable "local!temp". You are not interacting with this field by yourself , hence saveInto here is not working. saveInto only works when you interact with the field manually, means if you make any changes for the field. In your second code, you are saving "VM_ID_FK"  in submit button's saveInto parameter and this is clicked by the user, so everything under saveInto will be saved, hence you are able to save the value. One more thing i would recommend is not to use query entity in value parameter of the field, you can configure this in a local variable with refresh variable parameter.

Children