How to access id of selected card in saveInto parameter of card choice field?

a!cardLayout(
  contents: {
    a!localVariables(
      local!allWeather: rule!IMS_QR_getWeather(id: null),
      local!otherWeather,
      {
        a!cardChoiceField(
          label: "Weather Choices",
          labelPosition: "COLLAPSED",
          data: 'recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather',
          cardTemplate: a!cardTemplateBarTextStacked(
            id: fv!data['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{5a76435e-3c34-4bfc-9d4a-639d0639076a}id'],
            primaryText: fv!data['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{6264f67e-0086-4b15-a25c-b738d8a2aac1}labelEn'],
            /* To be replaced by translation set */
            icon: fv!data['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{513cbb34-3b72-4a09-a21e-adba417682bb}icon']
          ),
          value: ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping.fields.{1b4c7204-a0a3-4ac3-8a5b-044117440ce9}weather'],
          saveInto: a!save(
            ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping'],
            append(
              ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping'],
              'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition'(
              /* "weather" needs to be updated with selected card id */
                'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{1b4c7204-a0a3-4ac3-8a5b-044117440ce9}weather': save!value,
                'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{087f6896-59d4-4647-81fc-b30697f987b8}incidentReportId': null,
                'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{8300cc97-8931-4a46-a3ba-b533c0f28a7d}createdBy': loggedInUser(),
                'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{35ec86a4-aef0-452b-85e1-6fe17d03b2e4}createdOn': now(),
                'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{c4faca89-e4bf-4ffb-a794-5147471aeb08}modifiedBy': loggedInUser(),
                'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{8aa5315a-c9a4-405f-b45c-bd2f34909274}modifiedOn': now()
              )
            )
          ),
          align: "START",
          showShadow: false,
          validations: {}
        ),
        a!localVariables(
          local!otherIndex: if(
            a!isNotNullOrEmpty(
              ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping.fields.{1b4c7204-a0a3-4ac3-8a5b-044117440ce9}weather']
            ),
            wherecontains(
              tointeger(
                rule!IMS_RULE_General_indexWhere(
                  initialArray: local!allWeather['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{6264f67e-0086-4b15-a25c-b738d8a2aac1}labelEn'],
                  finalArray: local!allWeather['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{5a76435e-3c34-4bfc-9d4a-639d0639076a}id'],
                  value: "Other"
                )
              ),
              ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping.fields.{1b4c7204-a0a3-4ac3-8a5b-044117440ce9}weather']
            ),
            {}
          ),
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!textField(
                    label: "Weather Condition (Other)",
                    labelPosition: "ABOVE",
                    value: local!otherWeather,
                    saveInto: {
                      local!otherWeather,
                      a!save(
                        ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping'][local!otherIndex]['recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{7a41d798-0f2e-4ed4-990f-3ad18df6bc04}otherWeather'],
                        save!value
                      )
                    }
                  )
                },
                width: "MEDIUM"
              ),
              a!columnLayout()
            },
            showWhen: length(local!otherIndex) > 0
          )
        )
      }
    )
  },
  showWhen: ri!currentFormStep = 2,
  showBorder: false
)

I have a parent record with a child record (One to many mapping). In the UI, to select data for child record, we are using card choice field. Multiple selection is allowed. Now, on every selection, I want the relationship inside that parent record rule input value to be updated/appended with the newly selected card value (In the record format of child record - it includes saving default values like createdBy, createdOn, etc.). For this I am using record constructor and append function and saving that directly in relationship.

Now, I am unable to access the currently selected card id in save into so that I can save that value as well while constructing the child record.

Any pointers how to do that?

I have attached the code I tried so far.

  Discussion posts and replies are publicly visible

Parents Reply Children
  •  I tried something similar and it's working fine. Thanks

    a!cardLayout(
      contents: {
        a!localVariables(
          local!allWeather: rule!IMS_QR_getWeather(id: null),
          local!otherWeather,
          local!selectedWeather,
          {
            a!cardChoiceField(
              label: "Weather Choices",
              labelPosition: "COLLAPSED",
              data: 'recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather',
              cardTemplate: a!cardTemplateBarTextStacked(
                id: fv!data['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{5a76435e-3c34-4bfc-9d4a-639d0639076a}id'],
                primaryText: fv!data['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{6264f67e-0086-4b15-a25c-b738d8a2aac1}labelEn'],
                /* To be replaced by translation set */
                icon: fv!data['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{513cbb34-3b72-4a09-a21e-adba417682bb}icon']
              ),
              value: local!selectedWeather,
              saveInto: {
                local!selectedWeather,
                a!save(
                  ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping'],
                  append(
                    ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping'],
                    'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition'(
                      'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{1b4c7204-a0a3-4ac3-8a5b-044117440ce9}weather': save!value[length(save!value)],
                      'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{087f6896-59d4-4647-81fc-b30697f987b8}incidentReportId': null,
                      'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{8300cc97-8931-4a46-a3ba-b533c0f28a7d}createdBy': loggedInUser(),
                      'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{35ec86a4-aef0-452b-85e1-6fe17d03b2e4}createdOn': now(),
                      'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{c4faca89-e4bf-4ffb-a794-5147471aeb08}modifiedBy': loggedInUser(),
                      'recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{8aa5315a-c9a4-405f-b45c-bd2f34909274}modifiedOn': now()
                    )
                  )
                )
              },
              align: "START",
              showShadow: false,
              validations: {}
            ),
            a!localVariables(
              local!otherIndex: if(
                a!isNotNullOrEmpty(
                  ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping.fields.{1b4c7204-a0a3-4ac3-8a5b-044117440ce9}weather']
                ),
                wherecontains(
                  tointeger(
                    rule!IMS_RULE_General_indexWhere(
                      initialArray: local!allWeather['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{6264f67e-0086-4b15-a25c-b738d8a2aac1}labelEn'],
                      finalArray: local!allWeather['recordType!{0d9629bd-6e75-4c05-94e2-edfb817cb378}IMS Ref Weather.fields.{5a76435e-3c34-4bfc-9d4a-639d0639076a}id'],
                      value: "Other"
                    )
                  ),
                  ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping.fields.{1b4c7204-a0a3-4ac3-8a5b-044117440ce9}weather']
                ),
                {}
              ),
              a!columnsLayout(
                columns: {
                  a!columnLayout(
                    contents: {
                      a!textField(
                        label: "Weather Condition (Other)",
                        labelPosition: "ABOVE",
                        value: local!otherWeather,
                        saveInto: {
                          local!otherWeather,
                          a!save(
                            ri!mandatoryIncident['recordType!{b1f5fef5-db37-4e8e-826d-7f8c578856be}IMS Mandatory Incident Report.relationships.{5e822525-b6fe-4b47-b78b-fe13ceb92462}incidentWeatherConditionMapping'][local!otherIndex]['recordType!{c899c492-a6b1-4ba3-9e4d-30951e696e25}IMS Weather Condition.fields.{7a41d798-0f2e-4ed4-990f-3ad18df6bc04}otherWeather'],
                            save!value
                          )
                        }
                      )
                    },
                    width: "MEDIUM"
                  ),
                  a!columnLayout()
                },
                showWhen: length(local!otherIndex) > 0
              )
            )
          }
        )
      },
      showWhen: ri!currentFormStep = 2,
      showBorder: false
    )