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
  •  I am facing a weird issue in QA test after implementing the solution to main problem stated in this thread. Problem is when I am slowly selecting the multiple card choices one after other, then all values in the relationship are updating perfectly fine.

    But, in any case, if my speed of selection of card choices is high, then it persists only last selected card choice. I've hit the wall but not able to find out what's the issue here.

    Attached is the full code I implemented so far. Record references may need to be replaced with local dummy data to test.

    This is urgent, any help is really appreciated.

    a!localVariables(
      local!allWeather: rule!IMS_QR_getWeather(id: null),
      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: if(
            ri!readOnly,
            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'],
            local!selectedWeather
          ),
          saveInto: {
            a!save(local!selectedWeather, save!value),
            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: {},
          required: true,
          disabled: ri!readOnly
        ),
        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: 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'],
                    saveInto: 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'],
                    disabled: ri!readOnly
                  )
                },
                width: "MEDIUM"
              ),
              a!columnLayout()
            },
            showWhen: length(local!otherIndex) > 0
          )
        )
      }
    )

  • 0
    Certified Lead Developer
    in reply to tarunt0003

    you'll probably just need to find a way to simplify your save operation to avoid using this, which probably gets tripped up when the user clicks too fast...

    "save!value[length(save!value)],"

    Instead of constructing every member of the added record in the saveInto, try declaring a dynamic local variable that iterates over the list of local!selectedWeather (which would be a basic list that items get added to when clicked), and it sets up an entry for every current item in that list.  This approach should(?) be a bit mroe resistant against users spam-clicking items, since it'll always adjust to the total values in local!selectedWeather after the user stops clicking stuff.

Reply
  • 0
    Certified Lead Developer
    in reply to tarunt0003

    you'll probably just need to find a way to simplify your save operation to avoid using this, which probably gets tripped up when the user clicks too fast...

    "save!value[length(save!value)],"

    Instead of constructing every member of the added record in the saveInto, try declaring a dynamic local variable that iterates over the list of local!selectedWeather (which would be a basic list that items get added to when clicked), and it sets up an entry for every current item in that list.  This approach should(?) be a bit mroe resistant against users spam-clicking items, since it'll always adjust to the total values in local!selectedWeather after the user stops clicking stuff.

Children
  • Thanks  . I will try what you suggested. Previously, I tried a!foreach() in place of append(). But, I have one more usecase in it where I need to capture the "Other" value using textbox, which gets enabled only when user selects the card choice with name OTHER. I need to maintain that value as well on the same index where id for OTHER is stored. And looping approach was overriding values with new values. So, as a consequence I was losing the value in the record field corresponding to that text box.

    But, I will try with a new dynamic local variable and update you.