setChoiceValueByRecodeValue to set value of Already asked Question | XM Community
Skip to main content

Hi All,

 

I need to change the response of already asked question at the end of survey.

I am trying to use function setChoiceValueByRecodeValue(5, 'true') but with “this” as a prefix it will refer to the question on which js is being applied. I want to set the value to the question which is was already answered by respondent at the start of the survey.

Can some one help me in writing the correct syntax for my above requirement.

 

Thanks,

Salim

 

Just to further elaborate my question...

I have to change the response of a question which is already asked at the end of survey. 

With the function setChoiceValueByRecodeValue i guess it is possible but with below syntax, as we placed "this" it will set the value of the question on which this function is applied.

this.setChoiceValueByRecodeValue(5, 'true');

But here I need to refer to different question whcih is not present on current page and asked earlier, so how i can refer it using setChoiceValueByRecodeValue(5, 'true'). Please help me on this.

Thanks,
Salim


@Salim

You can’t refer to a previous question with JS. The question you are changing must be on the same page as your JS. The only way to change the answer would be to repeat the block containing the question in the survey flow.


Thanks @TomG for suggesting a work around.

But if i again ask that block in survey flow and the block is having multiple questions on same page, then how i can edit the response of any specific question of that block through js. Please help me in sorting this out, eagerly waiting for your suggestion.


You would need to write JS to hide all the questions in the block, change the answer to the question, and click the next button the second time the block is shown.


@TomG , actually i have more than one questions whose response i have to reset on a block that’s why finding a way to refer each question on the block separately through js.


@TomG , actually i have more than one questions whose response i have to reset on a block that’s why finding a way to refer each question on the block separately through js.

The solution is still the same - you would use JS to change the answer to multiple questions instead of one.


Hi @TomG 

I am facing one more challenge. I have a question on a page on which inpage logic is setup.

Due to this Inpage logic, the page is not being submitted with below code.

 

this.clickNextButton();

 

When i removed inpage logic, the page submission is working but not with InpPage logic. How can i resolve this, please help.


Hi @TomG 

I am facing one more challenge. I have a question on a page on which inpage logic is setup.

Due to this Inpage logic, the page is not being submitted with below code.

 

this.clickNextButton();

 

When i removed inpage logic, the page submission is working but not with InpPage logic. How can i resolve this, please help.

I’m guessing there is some type of validation on the hidden question. So your code will have to account for that and answer the hidden question as required.


There is no validation, just an inpage display logic is present and all the questions are non-mandatory. No validation on any of the question.


There is no validation, just an inpage display logic is present and all the questions are non-mandatory. No validation on any of the question.

In that case, my next guess is that it is a timing issue. If so, you’ll need to adjust the code to account for that. Try making sure the next button is there before clicking it.


Leave a Reply