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
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.
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" ) } )
Hello Jai_1441 Get the choice labels and choice values in a local. I would not recommend running it directly in the components.Then when you have the code, please do post it here as Stefan has mentioned for a better readability.
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*/ } ) } )
I don't see any error for the above code, other than having no context of the answer.
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.
Actually am fetching the choice values & choice labels from DB. If I am taking it from local than it worked fine only.
Yes, I meant running your expression rule or the iterations. This helps you understand what's going wrong in the locals.
Yes correct. thats why am saving the selected values using a!map() in rule rule!MWJ_QE_MultiCorrectOption_SelectedAnswer() to return a list. But still not able to save the selected values.
a!localVariables( local!count:count(split(rule!MWJ_qe_multiCorrect_fetchQuestion(),";")), local!selectedAnswer: a!forEach( items:enumerate(local!count), expression: a!map( /*Question:local!question[fv!index],*/ SelectedAnswer:null, DummyAnswer:null )), local!selectedAnswer, )