Dropdown null value issue

Hi ,

 

I have an issue with dropdown. I want to display current year by default in my year dropdown.

For that i have appended year with the year dataset but its giving me error.

/*placeholderLabel: "--Select a Year-- ",*/ - In this by default current year should be display and selected.

 

Below code i have in load().

local!year1: append(tointeger(todatasubset(
    local!data,
    a!pagingInfo(
      startIndex: 1,
      batchSize: - 1,
      sort: a!sortInfo(
        field: "year",
        ascending: false
      )
    )
  ),year(today()))),
  local!year: if(
    rule!APN_isBlank(
      local!data
    ),
    {},
   union(
      index(
        local!year1.data,
        "year"
      ),
      index(
        local!year1.data,
        "year"
      )
      
    )
  ),

 

a!dropdownField(
label: "Year",
labelPosition: "ABOVE",
/*placeholderLabel: "--Select a Year-- ",*/
choiceLabels: local!Year,
choiceValues: local!Year,
value: local!selectedYear,
saveInto: { local!selectedCycleYear }
)

 

But i am getting error. Could not display interface. Please check definition and inputs.
Interface Definition: Expression evaluation error at function a!dropdownField [line 190]: A dropdown component [label=Year”] has an invalid value for “value”. Value cannot be null.

 

If i un comment this section - /*placeholderLabel: "--Select a Year-- ",*/ 

than its working fine but as per my requirement i don't want to display this text , dropdown should populate with year data along with current year on top of that(In selected mode)

 

What could be the workaround of this problem.

  Discussion posts and replies are publicly visible

  • I tried to put null check also before this dropdown but after that its not showing this dropdown in case of local!selectedCycleYear null check and when i tried with local!year null than nothing is getting impact same error is coming.
  • 0
    A Score Level 1
    in reply to sauravk
    Hi Saurav,

    local!Year is list of years which contain current year (which you wan to be selected when form is loaded) right? If yes then did you try assigning the local!selectedYear=current year (which you wan to be selected when form is loaded) ?
  • can you share one liner code or modify this code as per your approach if possible
  • if(isnull(local!selectedYear),{},dropdown()) here i have assigned current year to selectedYear but its completing hiding that dropdown.
  • @sauravk: Can you please try below code snippet.

     

     

    load(
    local!data:{
    {id:1,name:"user1",year:2016},
    {id:2,name:"user2",year:2017}
    },
    local!selectedYear:year(
    today()
    ),
    local!selectedCycleYear,
    local!dataSubset:todatasubset(
    local!data,
    a!pagingInfo(
    startIndex: 1,
    batchSize: - 1,
    sort: a!sortInfo(
    field: "year",
    ascending: false
    )
    )
    ),
    local!year: if(
    rule!APN_isBlank(
    local!data
    ),
    {},
    rule!APN_distinct(append(
    tointeger(
    index(
    local!dataSubset.data,"year",null),
    local!selectedYear
    )
    ))
    ),
    a!formLayout(
    contents: {
    a!dropdownField(
    label: "Year",
    labelPosition: "ABOVE",
    /*placeholderLabel: "--Select a Year-- ",*/
    choiceLabels: local!Year,
    choiceValues: local!Year,
    value: local!selectedYear,
    saveInto: {
    local!selectedCycleYear
    }
    )
    }
    )
    )

  • Can you try below code

    load(
    local!currentYear:year(today()),
    local!years: append(
    a!forEach(
    {
    10,
    9,
    8,
    7,
    6,
    5,
    4,
    3,
    2,
    1
    },
    local!currentYear - fv!item
    ),
    local!currentYear,
    a!forEach(
    {
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10
    },
    fv!item + local!currentYear
    )
    ),
    local!selectedYear:local!currentYear,
    a!dropdownField(
    label: "Year",
    labelPosition: "ABOVE",
    placeholderLabel: "--Select a Year-- ",
    choiceLabels: local!years,
    choiceValues: local!years,
    value:local!selectedYear,
    saveInto: local!selectedYear
    )
    )
  • load(
      local!data: {
        {
          id: 1,
          name: "user1",
          year: 2016
        },
        {
          id: 2,
          name: "user2",
          year: 2017
        }
      },
      local!selectedYear: year(
        today()
      ),
      local!selectedCycleYear,
      local!dataSubset: todatasubset(
        local!data,
        a!pagingInfo(
          startIndex: 1,
          batchSize: - 1,
          sort: a!sortInfo(
            field: "year",
            ascending: false
          )
        )
      ),
      local!year: if(
        rule!APN_isBlank(
          local!data
        ),
        {},
        rule!APN_distinct(
          append(
            tointeger(
              index(
                local!dataSubset.data,
                "year",
                null
              ),
              local!selectedYear
            )
          )
        )
      ),
      a!formLayout(
        contents: {
          a!dropdownField(
            label: "Year",
            labelPosition: "ABOVE",
            /*placeholderLabel: "--Select a Year-- ",*/
            choiceLabels: local!Year,
            choiceValues: local!Year,
            value: local!selectedYear,
            saveInto: {
              local!selectedCycleYear
            }
          ),
          a!textField(local!selectedCycleYear)
        }
      )
    )

    I got one issue in this code. local!selectedCycleYear value is not saving for 2018 for rest year it is getting save.
    Plz add this a!textField(local!selectedCycleYear) n you will see result.

  • Can you have look now.

    load(
      
      local!data: {
        {
          id: 1,
          name: "user1",
          year: 2016
        },
        {
          id: 2,
          name: "user2",
          year: 2017
        }
      },
      /*local!selectedYear: year(
        today()
      ),*/
      local!selectedCycleYear: year(
        today()
      ),
      local!dataSubset: todatasubset(
        local!data,
        a!pagingInfo(
          startIndex: 1,
          batchSize: - 1,
          sort: a!sortInfo(
            field: "year",
            ascending: false
          )
        )
      ),
      local!year: if(
        rule!APN_isBlank(
          local!data
        ),
        {
          local!selectedCycleYear
        },
        rule!APN_distinct(
          append(
            tointeger(
              index(
                local!dataSubset.data,
                "year",
                null
              ),
              local!selectedCycleYear
            )
          )
        )
      ),
      a!formLayout(
        contents: {
          a!dropdownField(
            label: "Year",
            labelPosition: "ABOVE",
            /*placeholderLabel: "--Select a Year-- ",*/
            choiceLabels: local!Year,
            choiceValues: local!Year,
            value: local!selectedCycleYear,
            saveInto: {
              local!selectedCycleYear
            }
          ),
          a!textField(label:"Debug local!selectedCycleYear",value:local!selectedCycleYear,readOnly: true())
        }
      )
    )

    What is Diff b/w local!selectedYearand local!selectedCycleYear , If above code is fine Just remove unnecessary local variables

  • Plz find updated code.

    load(

    local!data: {
    {
    id: 1,
    name: "user1",
    year: 2016
    },
    {
    id: 2,
    name: "user2",
    year: 2017
    }
    },
    /*local!selectedYear: year(
    today()
    ),*/
    local!selectedCycleYear: year(
    today()
    ),
    local!dataSubset: todatasubset(
    local!data,
    a!pagingInfo(
    startIndex: 1,
    batchSize: - 1,
    sort: a!sortInfo(
    field: "year",
    ascending: false
    )
    )
    ),
    local!year: if(
    rule!APN_isBlank(
    local!data
    ),
    {
    local!selectedCycleYear
    },
    rule!APN_distinct(
    append(
    tointeger(
    index(
    local!dataSubset.data,
    "year",
    null
    ),
    local!selectedCycleYear
    )
    )
    )
    ),
    a!formLayout(
    contents: {
    a!dropdownField(
    label: "Year",
    labelPosition: "ABOVE",
    /*placeholderLabel: "--Select a Year-- ",*/
    choiceLabels: local!Year,
    choiceValues: local!Year,
    value: local!selectedCycleYear,
    saveInto: {
    local!selectedCycleYear,
    a!save(ri!year,local!selectedCycleYear)
    }
    ),
    a!textField(label:"Debug local!selectedCycleYear",value:ri!year,readOnly: true())
    }
    )
    )

    Have a look its not able to assign value in rule input variable. Sorry i forgot to add this in previous chat. I was about to ask this only. By mistake add wrong variable name.