Skip to main content
Participating Frequently
Jul 28, 2021 11:55 AM UTC
Solved

Why wont this save?

Hi,

So Im trying to get this code to save below into my ri! field but no matter what I do it will not save. Can someone please tell me whats wrong here?

    gayathris111098
    Inspiring
    Jul 28, 2021 12:18 PM UTC

    Hi

    Below sample may be helpful for this case,

    a!localVariables(
      local!firstItem_txt,
      local!secondItem_txt,
      local!thirItem_txt,
      local!combinedItem_txt,/*ri!orders.products*/
      {
        a!sectionLayout(
          label: "Section",
          contents: {
            a!columnsLayout(
              columns: {
                a!columnLayout(
                  contents: {
                    a!dropdownField(
                      label: "Dropdown 1",
                      labelPosition: "ABOVE",
                      placeholder: "--- Select a Value ---",
                      choiceLabels: {
                        "Option 1",
                        "Option 2",
                        "Option 3",
                        "Option 4",
                        "Option 5",
                        "Option 6",
                        "Option 7",
                        "Option 8",
                        "Option 9",
                        "Option 10",
                        "Option 11",
                        "Option 12"
                      },
                      choiceValues: {
                        "Option 1",
                        "Option 2",
                        "Option 3",
                        "Option 4",
                        "Option 5",
                        "Option 6",
                        "Option 7",
                        "Option 8",
                        "Option 9",
                        "Option 10",
                        "Option 11",
                        "Option 12"
                      },
                      value: local!firstItem_txt,
                      saveInto: {
                        local!firstItem_txt,
                        if(
                          or(
                            isnull(local!firstItem_txt),
                            isnull(local!secondItem_txt),
                            isnull(local!thirItem_txt)
                          ),
                          {},
                          a!save(
                            local!combinedItem_txt,
                            joinarray(
                              {
                                local!firstItem_txt,
                                local!secondItem_txt,
                                local!thirItem_txt
                              },
                              ","
                            )
                          )
                        )
                      }
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    a!dropdownField(
                      label: "Dropdown 2",
                      labelPosition: "ABOVE",
                      placeholder: "--- Select a Value ---",
                      choiceLabels: {
                        "Option 1",
                        "Option 2",
                        "Option 3",
                        "Option 4",
                        "Option 5",
                        "Option 6",
                        "Option 7",
                        "Option 8",
                        "Option 9",
                        "Option 10",
                        "Option 11",
                        "Option 12"
                      },
                      choiceValues: {
                        "Option 1",
                        "Option 2",
                        "Option 3",
                        "Option 4",
                        "Option 5",
                        "Option 6",
                        "Option 7",
                        "Option 8",
                        "Option 9",
                        "Option 10",
                        "Option 11",
                        "Option 12"
                      },
                      value: local!secondItem_txt,
                      saveInto: {
                        local!secondItem_txt,
                        if(
                          or(
                            isnull(local!firstItem_txt),
                            isnull(local!secondItem_txt),
                            isnull(local!thirItem_txt)
                          ),
                          {},
                          a!save(
                            local!combinedItem_txt,
                            joinarray(
                              {
                                local!firstItem_txt,
                                local!secondItem_txt,
                                local!thirItem_txt
                              },
                              ","
                            )
                          )
                        )
                      }
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    a!dropdownField(
                      label: "Dropdown 3",
                      labelPosition: "ABOVE",
                      placeholder: "--- Select a Value ---",
                      choiceLabels: {
                        "Option 1",
                        "Option 2",
                        "Option 3",
                        "Option 4",
                        "Option 5",
                        "Option 6",
                        "Option 7",
                        "Option 8",
                        "Option 9",
                        "Option 10",
                        "Option 11",
                        "Option 12"
                      },
                      choiceValues: {
                        "Option 1",
                        "Option 2",
                        "Option 3",
                        "Option 4",
                        "Option 5",
                        "Option 6",
                        "Option 7",
                        "Option 8",
                        "Option 9",
                        "Option 10",
                        "Option 11",
                        "Option 12"
                      },
                      value: local!thirItem_txt,
                      saveInto: {
                        local!thirItem_txt,
                        if(
                          or(
                            isnull(local!firstItem_txt),
                            isnull(local!secondItem_txt),
                            isnull(local!thirItem_txt)
                          ),
                          {},
                          a!save(
                            local!combinedItem_txt,
                            joinarray(
                              {
                                local!firstItem_txt,
                                local!secondItem_txt,
                                local!thirItem_txt
                              },
                              ","
                            )
                          )
                        )
                      }
                    )
                  }
                )
              }
            )
          }
        ),
        a!textField(
          showWhen: not(isnull(local!combinedItem_txt)),
          label: "Result",
          labelPosition: "ABOVE",
          readOnly: true,
          value: local!combinedItem_txt
        )
      }
    )

    5 replies

    gayathris111098
    Inspiring
    Jul 28, 2021 12:00 PM UTC

    Hi

    The expression in the saveInto parameter only evaluates when the user interacts with the component. Since you have made it as readOnly there is no user interaction hence so value is not populating. 

    Can you explain your usecase?

    gayathris111098
    Inspiring
    Jul 28, 2021 12:02 PM UTC

    If you want just populate this for DB writes, you can call it in the submit button saveInto like

    saveInto:{

    a!save(

    ri!orders.products, concat(

    ri!firstItem

    )

    )

    }

    Participating Frequently
    Jul 28, 2021 12:18 PM UTC

    Why do it there?