issue in dropdownFieldByIndex() when setting the value based on choiceLabels

Certified Associate Developer

My requirement is to display current month as default option in dropdown and user can change month value from dropdown if they want to change and for each month there should be integer value saved in Rule Input "selectedMonth", so I have applied dropdownFieldByIndex() function for this. If user select blank then it will revert it to current month but I am getting below issue:

SAIL Code:

local!currMonth: datetext(today(),"M"),
local!monthName: {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},

a!dropdownFieldByIndex(
label: "",
labelPosition: "ABOVE",
placeholder: "--Select Month--",
choiceLabels:union(local!monthName,local!monthName),
/*choiceValues: tointeger(union(local!monthValue,local!monthValue)),*/
value: if(rule!APN_isNotBlank(ri!selectedMonth),ri!selectedMonth,local!currMonth),
saveInto:ri!selectedMonth,
searchDisplay: "ON"
)

Can anyone help with this what is the issue?

  Discussion posts and replies are publicly visible

Parents
  • Like others have said, it doesn't seem to generate an error - however, I think there are a few changes you can make that would make your code easier to use and understand.

    1. The if() statement around the value isn't necessary and adds confusion. I typically just define a local variable with the default value and use that to set a dropdown with an initial value
    2. The union isn't necessary - you already have a unique list that is hardcoded. That being said, I still would recommend that you don't hardcode the list and instead determine it programatically.
    3. Your local!currMonth has the potential to return an error because the datetext() returns a text value but a!dropdownFieldByIndex() expects a text value. In this case it is able to cast, but it's still better to be consistent.

    Here's what I would do if I were in your situation:

    a!localVariables(
      local!month: month(today()),
      local!monthName: a!forEach(
        items: enumerate(12) + 1,
        expression: datetext(
          date(2021, fv!item, 1),
          "MMM"
        )
      ),
      a!dropdownFieldByIndex(
        placeholder: "--Select Month--",
        choiceLabels: local!monthName,
        value: local!month,
        saveInto: local!month,
        searchDisplay: "ON"
      )
    )

Reply
  • Like others have said, it doesn't seem to generate an error - however, I think there are a few changes you can make that would make your code easier to use and understand.

    1. The if() statement around the value isn't necessary and adds confusion. I typically just define a local variable with the default value and use that to set a dropdown with an initial value
    2. The union isn't necessary - you already have a unique list that is hardcoded. That being said, I still would recommend that you don't hardcode the list and instead determine it programatically.
    3. Your local!currMonth has the potential to return an error because the datetext() returns a text value but a!dropdownFieldByIndex() expects a text value. In this case it is able to cast, but it's still better to be consistent.

    Here's what I would do if I were in your situation:

    a!localVariables(
      local!month: month(today()),
      local!monthName: a!forEach(
        items: enumerate(12) + 1,
        expression: datetext(
          date(2021, fv!item, 1),
          "MMM"
        )
      ),
      a!dropdownFieldByIndex(
        placeholder: "--Select Month--",
        choiceLabels: local!monthName,
        value: local!month,
        saveInto: local!month,
        searchDisplay: "ON"
      )
    )

Children
No Data