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 Senior Developer
    in reply to Stefan Helzle

    a!localVariables(
      local!question: split(rule!MWJ_qe_multiCorrect_fetchQuestion(), ";"),
      local!option: split(rule!MWJ_qe_multipleCorect_options(), ";"),
      local!numberOfAnswers: 4,
      local!correctAnswer: rule!MWJ_qe_MultiCorrect_CorrectAnswer(),
      local!selectedAnswer: rule!MWJ_QE_MultiCorrectOption_SelectedAnswer(),
      local!Temp: stripwith(
        local!selectedAnswer.SelectedAnswer,
        "ZYWX[]:"
      ),
      /*local!result: intersection(local!correctAnswer, local!Temp),*/
      /*local!score: length(local!result),*/
    
      local!submit: false,
      {
        a!sectionLayout(
          label: "xxx",
          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"
                  ),
                  a!sectionLayout(
                    label: "",
                    contents: {
                      a!richTextDisplayField(
                        label: "Correct Answer : ",
                        labelPosition: "ABOVE",
                        value: a!richTextItem(
                          text: {
                            a!forEach(
                              items: local!currentQuestion,
                              expression: index(
                                local!correctAnswer,
                                if(
                                  local!currentQuestion = 0,
                                  "",
                                  fv!index + 1 * (local!currentQuestion - 1)
                                )
                              )
                            )
    
                          },
                          color: "POSITIVE",
                          size: "MEDIUM",
                          style: "EMPHASIS"
                        ),
                        showWhen: local!submit
    
                      )
    
                    }
                  )
    
                }
    
              )
            )
          },
          marginBelow: "STANDARD"
    
        ),
        /*a!timeDisplayField(*/
        /*label:"Time Lapsed",*/
        /*value:time(now())*/
        /*),*/
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              label: "Check Score",
              icon: "thumbs-up",
              iconPosition: "END",
              saveInto: {
    
                /*a!save(local!submit, save!value),*/
                /*a!save(ri!score.score,local!score)*/
              },
              /*submit: true,*/
    
              style: "GHOST"
            ),
            a!buttonWidget(
              label:"close",
              value:"close",
              saveInto: ri!buttonAction,
              submit:true,
              style: "SOLID"
    
    
            )
    
          },
          align: "CENTER"
    
        ),
        a!sectionLayout(
          labelColor: "POSITIVE",
          contents: {
            a!columnsLayout(
              columns: {
                a!columnLayout(
                  contents: {
                    a!richTextDisplayField(
                      labelPosition: "ADJACENT",
    
                      value:{a!richTextItem(
                        text: "Your Score is  ",
                        color: "ACCENT",
                        size: "LARGE",
                        style: "STRONG"
    
                      ),
                      a!richTextItem(
                        /*text: { local!score },*/
                        color: "ACCENT",
                        size: "LARGE",
                        style: "STRONG"
    
    
                      )},
                      showWhen: local!submit,
                      marginAbove: "STANDARD"
    
                    )
                  }
                )
    
              }
            )
          },
          isInitiallyCollapsed: true,
          dividerWeight: "MEDIUM",
          dividerColor: "ACCENT",
          marginAbove: "STANDARD"
        )
    
    
      }
    )

  • 0
    Certified Senior Developer
    in reply to Jai_1441

    I had used index() here & now am able to select multiple answers for a single question but if i select the answer for another question than the first selected answer gets vanished. Is there any way to resolve this and store all the selected values in local?

    updated code-

    value: index(local!selectedAnswer.SelectedAnswer,local!currentQuestion),
    saveInto: a!save(
                    index(local!selectedAnswer.SelectedAnswer,local!currentQuestion),
                    save!value
                    ),

Reply
  • 0
    Certified Senior Developer
    in reply to Jai_1441

    I had used index() here & now am able to select multiple answers for a single question but if i select the answer for another question than the first selected answer gets vanished. Is there any way to resolve this and store all the selected values in local?

    updated code-

    value: index(local!selectedAnswer.SelectedAnswer,local!currentQuestion),
    saveInto: a!save(
                    index(local!selectedAnswer.SelectedAnswer,local!currentQuestion),
                    save!value
                    ),

Children