Dropdown field throwing an error as " Choice index 4 is out of bounds. The choice index must be between 1 and 3"

I am getting following error when i fetch some value of dropdown from database.....when  i mention "value" property of a!dropdownField following error get populated....

Interface Definition: Expression evaluation error at function a!forEach [line 46]: Error in a!forEach() expression during iteration 1 with identifier 1: Expression evaluation error at function a!dropdownField [line 70]: A dropdown component [label="option 1"] has an invalid value for "value". Choice index 4 is out of bounds. The choice index must be between 1 and 3

Here is my code(Options are coming from the Database):-


a!dropdownField(
label: "option " & fv!index,
placeholderLabel: "-- Select Answer -- ",
choiceLabels: fv!item.SetAnsCDT.Options,
choiceValues: fv!item.SetAnsCDT.Id,
value: fv!item.SetAnsCDT.Id,
saveInto: ri!setUpQueResponse.SetAnsId,
required: true
)

 

whole code is given below:-

 

load(
/*rule!DDG_getSetupQuestions()*/
local!ques: rule!DDG_getSetupQuestions(),
/*local!setUpResponse: rule!DDG_SetupQueResponseRule(),*/
/*local!answoption: rule!DDG_getSetQueAnsOption(6),*/
a!formLayout(
label: "SetUp Questions for " & ri!OppData.Opportunity_Id,
contents: {
a!columnsLayout(
columns: {
a!columnLayout(
contents: {
a!boxLayout(
label: "Questions",
contents: {
a!gridLayout(
totalCount: count(
local!ques
),
headerCells: {
a!gridLayoutHeaderCell(
label: "Sr. No."
),
a!gridLayoutHeaderCell(
label: "Questions"
),
a!gridLayoutHeaderCell(
label: "Answer"
)/* For the "Remove" column a!gridLayoutHeaderCell(label: "" ) */

},
/* Only needed when some columns need to be narrow */
columnConfigs: {
a!gridLayoutColumnConfig(
width: "NARROW"
),
a!gridLayoutColumnConfig(
width: "DISTRIBUTE",
weight: 3
),
a!gridLayoutColumnConfig(
width: "DISTRIBUTE",
weight: 3
)
},
rows: a!forEach(
items: local!ques,
expression: a!gridRowLayout(
id: fv!index,
contents: {
/* For the Sr.NO Column*/
a!textField(
/* Labels are not visible in grid cells but are necessary to meet accessibility requirements */
label: "Que " & fv!index,
value: fv!index,
saveInto: fv!index,
required: true,
readOnly: true
),
/* For the Question Text Column*/
/*fv!item.ID & "Q." & fv!index & " " & */
a!textField(
label: "QueText " & fv!index,
required: true,
value: fv!item.QuestionText,
saveInto: ri!setUpQueResponse.SetQuestId,
readOnly: true
),
/* For the Answer Option Column*/
a!dropdownField(
label: "option " & fv!index,
placeholderLabel: "-- Select Answer -- ",
choiceLabels: fv!item.SetAnsCDT.Options,
choiceValues: fv!item.SetAnsCDT.Id,
value: fv!item.SetAnsCDT.Id,
saveInto: ri!setUpQueResponse.SetAnsId,
required: true
)
}
)
),
addRowlink: a!dynamicLink(
/*label: "ADD",*/
value: {
startDate: today() + 1
},
saveInto: {
a!save(
ri!setUpQueResponse,
append(
ri!setUpQueResponse,
save!value
)
)
}
)
)
},
style: "#AED6F1",
marginBelow: "STANDARD"
)
}
)
}
)
},
buttons: a!buttonLayout(
primaryButtons: {
a!buttonWidget(
label: "Submit",
submit: true,
style: "PRIMARY"
)
},
secondaryButtons: {
a!buttonWidget(
label: "Cancel",
value: true,
saveInto: ri!cancel,
submit: true,
style: "NORMAL",
validate: false
)
}
)
)
)

 

 

Please provide the solution....

  Discussion posts and replies are publicly visible

  • Hi ,

    Please check the Database values that is coming. It is trying to access 4th index which is not present or could be null.
  • Hey Ekansh Jain thanks for reply,

    I already checked the database values and data is coming or not on interface, so these are clear things...
  • 0
    A Score Level 2
    in reply to amitb0004

    Hi,

    Not sure on what your data is just tried with sample data. Worked fine.

    a!dropdownField(
    label: "option " & fv!index,
    placeholderLabel: "-- Select Answer -- ",
    choiceLabels: fv!item.SetAnsCDT.Options,
    choiceValues: fv!item.SetAnsCDT.Id,
    value: ri!setUpQueResponse.SetAnsId,
    saveInto: ri!setUpQueResponse.SetAnsId,
    required: true
    )

    Change the value parameter to hold the same as saveInto one. Rest depends on data.

    load(
    /*rule!DDG_getSetupQuestions()*/
    local!ques: {
    {
    QuestionText: "a",
    SetAnsCDT: {Options:{ 1,2,3},Id: {1,2,3}}
    },
    {
    QuestionText: "c",
    SetAnsCDT: {Options:{ 1,2,3},Id: {1,2,3}}
    }
    },
    /*local!setUpResponse: rule!DDG_SetupQueResponseRule(),*/
    /*local!answoption: rule!DDG_getSetQueAnsOption(6),*/
    a!formLayout(
    label: "SetUp Questions for " & ri!OppData.Opportunity_Id,
    contents: {
    a!columnsLayout(
    columns: {
    a!columnLayout(
    contents: {
    a!boxLayout(
    label: "Questions",
    contents: {
    a!gridLayout(
    totalCount: count(
    local!ques
    ),
    headerCells: {
    a!gridLayoutHeaderCell(
    label: "Sr. No."
    ),
    a!gridLayoutHeaderCell(
    label: "Questions"
    ),
    a!gridLayoutHeaderCell(
    label: "Answer"
    )/* For the "Remove" column a!gridLayoutHeaderCell(label: "" ) */

    },
    /* Only needed when some columns need to be narrow */
    columnConfigs: {
    a!gridLayoutColumnConfig(
    width: "NARROW"
    ),
    a!gridLayoutColumnConfig(
    width: "DISTRIBUTE",
    weight: 3
    ),
    a!gridLayoutColumnConfig(
    width: "DISTRIBUTE",
    weight: 3
    )
    },
    rows: a!forEach(
    items: local!ques,
    expression: a!gridRowLayout(
    id: fv!index,
    contents: {
    /* For the Sr.NO Column*/
    a!textField(
    /* Labels are not visible in grid cells but are necessary to meet accessibility requirements */
    label: "Que " & fv!index,
    value: fv!index,
    saveInto: fv!index,
    required: true,
    readOnly: true
    ),
    /* For the Question Text Column*/
    /*fv!item.ID & "Q." & fv!index & " " & */
    a!textField(
    label: "QueText " & fv!index,
    required: true,
    value: fv!item.QuestionText,
    saveInto: ri!setUpQueResponse.SetQuestId,
    readOnly: true
    ),
    /* For the Answer Option Column*/
    a!dropdownField(
    label: "option " & fv!index,
    placeholderLabel: "-- Select Answer -- ",
    choiceLabels: fv!item.SetAnsCDT.Options,
    choiceValues: fv!item.SetAnsCDT.Id,
    value: ri!setUpQueResponse.SetAnsId,
    saveInto: ri!setUpQueResponse.SetAnsId,
    required: true
    )
    }
    )
    ),
    addRowlink: a!dynamicLink(
    /*label: "ADD",*/
    value: {
    startDate: today() + 1
    },
    saveInto: {
    a!save(
    ri!setUpQueResponse,
    append(
    ri!setUpQueResponse,
    save!value
    )
    )
    }
    )
    )
    },
    style: "#AED6F1",
    marginBelow: "STANDARD"
    )
    }
    )
    }
    )
    },
    buttons: a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Submit",
    submit: true,
    style: "PRIMARY"
    )
    },
    secondaryButtons: {
    a!buttonWidget(
    label: "Cancel",
    value: true,
    saveInto: ri!cancel,
    submit: true,
    style: "NORMAL",
    validate: false
    )
    }
    )
    )
    )

  • That's true it will work,

    Now i got exact problem that....

    i used editable grid and while fetching data from database the rule input is not accepting the multiple data and it's overriding the data, so when i select option from second drop-down which has different value than first drop-down value, when i select second value it reflects to first also which is not present , that's why error is display...

    Thanks for your help....

  • Hi May I know how did you resolve this, I am getting same error

  • 0
    Certified Senior Developer
    in reply to mkhaiserulla

    This error occurs when multiple values are passed to a Dropdown (Which is of Single Select).

    If the expectation is displaying multiple values in that dropdown then using the Multiselect Dropdown component resolves the error or only one option should be passed to the dropdown component.