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

  • I've copied your code into the Appian environment I am working in and it seems to work for me .The only thing I had to change was that I don't have access to rule!APN_isNotBlank:

    a!localVariables(
      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!GBL_isNotBlank(ri!selectedMonth),ri!selectedMonth,local!currMonth),
        saveInto:ri!selectedMonth,
        searchDisplay: "ON"
      )
    )

    ...otherwise it's identical to what you've provided., I do not see an error.

    There is a possibility that you're passing 0 in the value of ri!selectedMonth from, say, a process that has this User Interface inside a User Input Task...in which case you need to default the value to null and not 0

  • 0
    Certified Senior Developer

    Hi Amrit,

    try to use the following: (it makes the code way more readable for other community members)



    1.) i dont see a reason for a union() at the choicelables ;)
    2.)I used a slightly different code and it was working pretty fine as i can tell. it just jumps back to "Nov". 

    a!localVariables(
      local!currMonth: datetext(today(),"M"),
      local!monthName: {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},
      local!selectedMonth,
      a!dropdownFieldByIndex(
        label: "",
        labelPosition: "ABOVE",
        placeholder: "--Select Month--",
        choiceLabels:local!monthName,,
        /*choiceValues: tointeger(union(local!monthValue,local!monthValue)),*/
        value: if(not(isnull(local!selectedMonth)),local!selectedMonth,local!currMonth),
        saveInto:local!selectedMonth,
        searchDisplay: "ON"
      )
    )

    Did you use "0" (integer) as rule input value? 

  • 0
    Certified Lead Developer

    Are you aware that regardless of whether you code works or not, the actual value of your rule input will not be updated to the current month in case the user selects no value?

    I recommend to put that logic into the saveInto. Add an a!save() to check for the selected value and in case of NULL, write the current month into the rule input.

  • 0
    Certified Senior Developer
    in reply to Stewart Burchell

    hahah i am pretty happy that we replied the same suggestion :D

  • 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"
      )
    )

  • 0
    Certified Associate Developer
    in reply to Stewart Burchell

    : Thanks for your response. I am passing the ri!selectedMonth in UserInputTask through Process model then I am getting error. What steps should I apply to fix the issue.

  • Where you are mapping the pv!selectedMonth into your Interface (inside the data mapping of the User Input Task) default the value to null.

  • 0
    Certified Senior Developer
    in reply to Stewart Burchell

    isn't the default value of a pv of type integer = 0? 

  • Yes. So you have to override if you want to pass this to the User Interface. Or, as an alternative, catch it in the rule input in the Interface and, if set to 0, override it to null. Or set it to the current month value if it's initialized to 0. Or any other of a dozen ways to skin a proverbial feline!