Issues with value and saveInto parameter in a!checkboxfield()

Certified Senior Developer

In the code below, I am not able to save the selected values. If i am selecting multiple values for a single question than I am getting below error- 

"Interface Definition: Expression evaluation error at function a!forEach [line 19]: Error in a!forEach() expression during iteration 2: Expression evaluation error at function a!checkboxField [line 27]: Rule 'l' has 1 parameters, but instead passed 2 parameters."

I had highlighted the code where the code needs some correction. NOTE- This code worked perfectly fine for a!RadiobuttonField() but not able to save values while using a!CheckBoxField()

a!localVariables(
local!question: /*calling QE rule to fetch the questions*/
local!option: /*calling QE rule to fetch the options*/
local!numberOfAnswers: 4,
local!correctAnswer: /*calling QE rule to fetch the correct Answer*/
local!selectedAnswer: rule!MWJ_MultiCorrectOption_SelectedAnswer(),  ///// this code is written below.

),

{
a!sectionLayout(
label: "",
contents: {
a!forEach(
items: local!question,
expression: a!localVariables(
local!currentQuestion: fv!index,
{
a!columnsLayout(
columns: {
a!columnLayout(
contents: a!checkboxField(
choiceLabels: {
a!forEach(
items: enumerate(local!numberOfAnswers),
expression: index(
split(stripwith(local!option, "[]ZYWX:"), ","),
if(
local!currentQuestion = 0,
fv!index,
fv!index + local!numberOfAnswers * (local!currentQuestion - 1)
)
)
)
},
choiceValues: {
a!forEach(
items: enumerate(local!numberOfAnswers),
expression: index(
split(local!option, ","),
if(
local!currentQuestion = 0,
fv!item,
fv!index + local!numberOfAnswers * (local!currentQuestion - 1)
)
)
)
},
label: fv!index & ". " & fv!item,
labelPosition: "ABOVE",
value: local!selectedAnswer.SelectedAnswer[local!currentQuestion],
saveInto:
a!save(
local!selectedAnswer.SelectedAnswer[local!currentQuestion],
save!value
),
validations: {}
)
)

},
alignVertical: "TOP"
),

------------------------------------------------------------------------------------

rule!MWJ_MultiCorrectOption_SelectedAnswer(),


a!localVariables(
local!count:count(split(rule!MWJ_multiCorrect_fetchQuestion(),";")),
local!selectedAnswer:
a!forEach(
items:enumerate(local!count),
expression:

a!map(
SelectedAnswer:null,
DummyAnswer:null
)),
local!selectedAnswer,
)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I suggest to follow a structured problem solving approach. Reduce the code to the bare working/non-working minimum to understand what is going wrong. Then fix it and build back up to the final solution.

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    I tried this same using a!map and it also worked perfectly fine. 

    a!localVariables(
    
      local!InputData: {
        a!map(
          Questions:"What is CDT",
          Options:{
            "a",
            "b",
            "c",
            "d"
          },
          Selected:null,
          CorrectAnswers:"b"
        ),
        a!map(
          Questions:"What is expression",
          Options:{
            "e",
            "f",
            "g",
            "h"
          },
          Selected:null,
          CorrectAnswers:"g"
        ),
        a!map(
          Questions:"What is Interface",
          Options:{
            "i",
            "j",
            "k",
            "l"
          },
          Selected:null,
          CorrectAnswers:"k"
        )
      },
      local!SelectedAnswers:local!InputData.selectedAnswers,
      /*local!CorrectAnswer:local!InputData.CorrectAnswers,*/
      /*local!Results:{intersection(local!CorrectAnswer,local!SelectedAnswers)},*/
      /*local!Score:length(local!Results),*/
    
      {
        a!sectionLayout(
          label: "Quize Paper",
    
          contents: {
    
            a!forEach(
              items:local!InputData,
              expression: {
                a!checkboxField(
                  choiceLabels: fv!item.Options,
                  choiceValues: fv!item.Options,
                  label: fv!item.Questions,
                  labelPosition: "ABOVE",
                  value:fv!item.selectedAnswers,
                  saveInto: {
                    a!save(fv!item.selectedAnswers,save!value)
                  },
                  choiceLayout: "STACKED",
                  validations: {}
                )
              }
            )
          }
        ),
        a!richTextDisplayField(
          labelPosition: "COLLAPSED",
          value: {
            /*local!Score*/
          }
        )
      }
    
    )

  • 0
    Certified Senior Developer
    in reply to Jai_1441

    I don't see any error for the above code, other than having no context of the answer. 

  • 0
    Certified Lead Developer
    in reply to Jai_1441

    I understand. The difference between a radiobuttonfield and a checkboxfield is, that checkboxes always return a list. That might break same related logic in your code.

Reply Children