Saving two address values in one CDT

Certified Associate Developer

Hi,

I have a address cdt . In the interface below i have two section temporary and permanant address.

So when i check box ( i,e : is temporary address same as permanent address) the address should be saved .

my requirement is : if the check box is not selected

both the temporary address and permanent address should be save and if its selected both the address saved. But it should be saved in the same cdt

So can anyone help me on how to solve this

a!localVariables(
  local!temporaryAddress:'type!{urn:com:appian:types:KYC}KYC_addressDetails'(),
  local!permanentAddress:'type!{urn:com:appian:types:KYC}KYC_addressDetails'(),
a!formLayout(
  label: "Customer Address Details",
  contents: {
    a!sectionLayout(
      label: "Temporary Address",
      contents: {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Address Line1",
                  labelPosition: if(
                    ri!button_txt,
                    "ADJACENT",
                    "ABOVE"
                  ),
                  placeholder: "Enter Your Address Line1",
                  value: ri!temporaryAddress.line1,
                  saveInto: ri!temporaryAddress.line1,
                  characterLimit: 255
                  
                
                 /* validations: if(regexmatch("^[a-zA-Z ]*$",ri!KYC_addressDetails.line1),null,"Enter only text")*/



                )
              }
            ),
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Address Line2",
                  labelPosition: if(
                    ri!button_txt,
                    "ADJACENT",
                    "ABOVE"
                  ),
                  placeholder: "Enter Your Address Line2",
                  value:ri!temporaryAddress.line2,
                  saveInto: ri!temporaryAddress.line2,
                  characterLimit: 255
                  /*readOnly: ri!button_txt*/,
                  required: true
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!KYC_addressDetails.line2),null,"Enter only text")*/
                )
              }
            )
          }
        ),
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!textField(
                  label: "City",
                  labelPosition: if(
                    ri!button_txt,
                    "ADJACENT",
                    "ABOVE"
                  ),
                  placeholder: "Enter Your City",
                  value:ri!temporaryAddress.city,
                  saveInto: ri!temporaryAddress.city,
                  characterLimit: 255
                  /*readOnly: ri!button_txt*/,
                  required: true
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!KYC_addressDetails.city),null,"Enter only text")*/
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!textField(
                  label: "State",
                  labelPosition: if(
                    ri!button_txt,
                    "ADJACENT",
                    "ABOVE"
                  ),
                  placeholder: "Enter Your State",
                  value: ri!temporaryAddress.state,
                  saveInto: ri!temporaryAddress.state,
                  characterLimit: 255
                  /*readOnly: ri!button_txt*/,
                  required: true
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!KYC_addressDetails.state),null,"Enter only text")*/
                )
              }
            )
          }
        )
      },
      isCollapsible: true
    ),
    a!columnsLayout(
      columns: {
        a!columnLayout(
          contents: {
            a!textField(
              label: "Country",
              labelPosition: if(
                ri!button_txt,
                "ADJACENT",
                "ABOVE"
              ),
              placeholder: "Enter Your Country",
              value: ri!temporaryAddress.country,
              saveInto:ri!temporaryAddress.country,
              characterLimit: 255
              /*readOnly: ri!button_txt*/,
              required: true
              /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!KYC_addressDetails.country),null,"Enter only text")*/
            )
          }
        ),
        a!columnLayout(
          contents: {
            a!integerField(
              label: "Zip Code",
              labelPosition: if(
                ri!button_txt,
                "ADJACENT",
                "ABOVE"
              ),
              placeholder: "Enter Your Zip Code",
              value: ri!temporaryAddress.zipCode,
              saveInto:ri!temporaryAddress.zipCode
              /*readOnly: ri!button_txt*/,
              required: true
            )
          }
        )
      }
    ),
    a!checkboxField(
      label: "",
      labelPosition: "ABOVE",
      choiceLabels: {"Temporary Address is the Permanent Address"},
      choiceValues: {true},
      saveInto: a!save(
        ri!permanentAddress,
        ri!temporaryAddress
        ),
      validations: {}
    ),
    a!sectionLayout(
      label: "Permanent ",
      contents: {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Address Line1",
                  labelPosition: "ABOVE",
                  placeholder: "Enter Your Permanent Address Line1",
                  value: ri!permanentAddress.line1,
                  saveInto: ri!permanentAddress.line1,
                  refreshAfter: "UNFOCUS"
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!permanentAddress.line1),null,"Enter only text")*/
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Address Line2",
                  labelPosition: "ABOVE",
                  placeholder: "Enter Your Permanent Address Line2",
                  value:  ri!permanentAddress.line2,
                  saveInto:  ri!permanentAddress.line2,
                  refreshAfter: "UNFOCUS"
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!permanentAddress.line2),null,"Enter only text")*/
                )
              }
            )
          }
        ),
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Country",
                  labelPosition: "ABOVE",
                  placeholder: "Enter Your Country",
                  value:  ri!permanentAddress.country,
                  saveInto:  ri!permanentAddress.country,
                  refreshAfter: "UNFOCUS"
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!permanentAddress.country),null,"Enter only text")*/
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!textField(
                  label: "City",
                  labelPosition: "ABOVE",
                  placeholder: "Enter Your City",
                  value:  ri!permanentAddress.city,
                  saveInto:  ri!permanentAddress.city,
                  refreshAfter: "UNFOCUS"
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!permanentAddress.city),null,"Enter only text")*/
                )
              }
            )
          }
        ),
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!integerField(
                  label: "Zip Code",
                  labelPosition: "ABOVE",
                  placeholder: "Enter Your Zip Code",
                  value:  ri!permanentAddress.zipcode,
                  saveInto:  ri!permanentAddress.zipcode,
                  refreshAfter: "UNFOCUS",
                  validations: {}
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!textField(
                  label: "State",
                  labelPosition: "ABOVE",
                  placeholder: "Enter Your State",
                  value: ri!permanentAddress.state,
                  saveInto: ri!permanentAddress.state,
                  refreshAfter: "UNFOCUS"
                  /*validations: if(regexmatch("^[a-zA-Z ]*$",ri!permanentAddress.state),null,"Enter only text")*/
                )
              }
            )
          }
        )
      },
      isCollapsible: true
    )

    
  },
  buttons: a!buttonLayout(
    primaryButtons: {
      a!buttonWidget(
        label: "Next",
        value: true,
        saveInto:{
          a!save(ri!button_txt,ri!button_txt+1),
        a!save(ri!KYC_addressDetails,local!temporaryAddress),
        a!save(ri!KYC_addressDetails,local!permanentAddress)

        },
        style: "PRIMARY",
        validate: true
      )
    },
    secondaryButtons: {
      a!buttonWidget(
        label: "Go back",
        value: "false",
        saveInto: a!save(ri!button_txt,ri!button_txt-1),
        submit: false,
        style: "NORMAL",
        validate: false
      )
    }

  )

)
)

  Discussion posts and replies are publicly visible