Question on using SAIL to pull information from DB

Hi

I am working on version 16.1.

I have a scenario where I want to display names of fruits in my drop down on SAIL whose values I am getting from DB.
In DB there are four distinct fruit names i.e. Apple, Orange, Banana, Mango and I am fetching these values via. query rule on my SAIL interface itself.
The SAIL interface rule is:
                                                                      load(
                                                                                 local!fruit,
                                                                                 local!dropDownValues:union(rule!Get_FruitData().fruitname,rule!Get_FruitData().fruitname),
                                                                                 a!formLayout(
                                                                                          label:"Drop Down Test",
                                                                                          firstColumnContents:{
                                                                                           a!dropdownField(
                                                                                                    label:"Fruit Names",
                                                                                                    placeholderLabel:"Select a fruit",
                                                                                                    choiceLabels:local!dropDownValues,
                                                                                                    choiceValues:local!dropDownValues,
                                                                                                    value:ri!fruit,
                                                                                                    saveInto:{ri!fruit
                                                                                                    }
                                                                                           )
                                                                                          },
                                                                                          buttons:a!buttonLayout(
                                                                                           primaryButtons:{
                                                                                                    a!buttonWidgetSubmit(
                                                  ...

OriginalPostID-211459

OriginalPostID-211459

  Discussion posts and replies are publicly visible

  • ...                                                   label:"Submit",
                                                                                                         value:"Submit"
                                                                                                        )
                                                                                               }
                                                                                              )
                                                                                     )
                                                                          )

                                                                          
    Now I have run 1 instance of my PM and from this drop down I selected Mango and rather than submitting the form, I have clicked on Tasks Tab i.e. left the form as it is after selecting Mango from it.
    Now before reopening the form, I have removed Mango from backend and then when I try to open the form, I get an error (PFA screenshot).
    This error is expected as there is now a discrepancy between choice labels and choice values.
    Is there a way to handle such a situation.

    Thanks in advance!!
  • Have you clicked on the save changes which will be present in the left pane while you performing some operations on task?
  • save that in to a local and then save the same thing in ri!fruit using a!save. I encountered same issue some time back.
  • Thank you pavang for replying!!

    No I didn't click on Save Changes earlier but now when I clicked on it I didn't get the error.
    I will be obliged if you could explain the importance of Save Changes and if user does not click on it he will get an error so is there a way to handle this? Also expecting a basic user to always click on Save Changes would be a little difficult.

    Thanks in advance!!
  • Thank you sparshs for replying!!

    I made the following modification in my code as per your suggestion:

                                                      load(
                                                                local!fruit,
                                                                local!dropDownValues:union(rule!Get_FruitData().fruitname,rule!Get_FruitData().fruitname),
                                                                                     a!formLayout(
                                                                                              label:"Drop Down Test",
                                                                                              firstColumnContents:{
                                                                                               a!dropdownField(
                                                                                                        label:"Fruit Names",
                                                                                                        placeholderLabel:"Select a fruit",
                                                                                                        choiceLabels:local!dropDownValues,
                                                                                                        choiceValues:local!dropDownValues,
                                                                                                        value:local!fruit,
                                                                                                        saveInto:{local!fruit,
                                                                                                        a!save(ri!fruit,local!fruit)
                                                                                                        }
                                                                                               )
                                                                                              },
                                                                                              buttons:a!buttonLayout(
                                                                                               primaryButtons:{
                                                                                                        a!buttonWidgetSubmit(
                                                                                                        label:"Submit",
                                                                                                         value:"Submit"
                                                                                                        )
                                                                                               }
                                                                                              )
                                                                                     )
                                                                )


    So now when I came back to my task's open instance I didn't get the error.
    Any more suggestions for the same, both Save Changes thing and saveInto local! worked.
  • @komalc - Can you try value:if(contains(local!dropDownValues,ri!fruit),ri!fruit,null) for value field. Also you are calling the query rule twice. It is best practice to call the query rule or entity once and save the data in local variables to use it later.
  • @konalc - if you use saveinto local! - and if you click save changes it will not save the data on the form. If you are okay with this behaviour where save changes should not work then you can go ahead with saveInto local!. But if you are allowing users to save form changes using out of the box Save changes feature you have to make sure your data is stored in rule inputs and not in local variables.
  • @komalC: No more suggestions. You are welcome.

    @sagar: when the user will select some value from dropdown then value gets in to both local and ri!fruit at the same time. So i did not understand your point why she cannot use local!fruit to save data.
  • Thank you @sagarl511 for replying!!

    I get your point of using Save Changes feature.
    I tried with
    value:if(contains(local!dropDownValues,ri!fruit),ri!fruit,null) for value field
    and it is working fine.
  • As you said, when the choice value gets removed/modified in the back end, existing instances having those values will create issue when rendering.

    You can do two things,

    1. When rendering the dropdown component you can simply ignore the previously selected value and force the user to select a new value again from the dropdown.

    a!dropdownField(
              label:"Fruit Names",
              placeholderLabel:"Select a fruit",
              choiceLabels:local!dropDownValues,
              choiceValues:local!dropDownValues,
              value: if(and(not(rule!APN_isBlank(local!fruit)), contains(local!dropDownValues, local!fruit)), local!fruit, null),
              saveInto:{
                        local!fruit,
                        a!save(ri!fruit,local!fruit)
              }
    )

    2. If you feel that will affect user experience (value getting disappeared suddenly), you can compute the same logic in a local variable and display a warning message to the user saying, the choice value was modified and is no longer available for selection