Store last answered questionnumber into an embedded data field of an unfinished response | XM Community
Skip to main content
Solved

Store last answered questionnumber into an embedded data field of an unfinished response


Nico_Leussink
Level 2 ●●
Forum|alt.badge.img+5
In a survey I have set the option of partial completed responses set to recorded responses after 4 hours after the respondents start of survey. What I like to have is an embedded data field called 'LastQuestion' containing the last used question number. Like the column in the Data & Analysis tab under Responses in Progress where a column Last Question exists. Is such an option possible?

Best answer by TomG

Add "LastQuestion" as an embedded data field in the survey flow and this JS to the header inside a `<script>` tag: ``` Qualtrics.SurveyEngine.addOnload(function() { Qualtrics.SurveyEngine.setEmbeddedData("LastQuestion", jQuery(".QuestionOuter:last").attr("id")); }); ``` It will save the QID of the last question on the last page where they clicked Next.
View original

15 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5929 replies
  • Answer
  • March 13, 2020
Add "LastQuestion" as an embedded data field in the survey flow and this JS to the header inside a `<script>` tag: ``` Qualtrics.SurveyEngine.addOnload(function() { Qualtrics.SurveyEngine.setEmbeddedData("LastQuestion", jQuery(".QuestionOuter:last").attr("id")); }); ``` It will save the QID of the last question on the last page where they clicked Next.

Nico_Leussink
Level 2 ●●
Forum|alt.badge.img+5
  • Author
  • Level 2 ●●
  • 24 replies
  • March 13, 2020
Thanks! This works!

Forum|alt.badge.img+1
  • 3 replies
  • February 9, 2022

Hi guys,

I have the same problem as Nico_Leussink . Where is it possible to add JS to the survey flow? And can you detail what the "header" is please?
There is no solution to add the "Last Answer" as embedded data in the survey flow without JS?

Thanks by advance,
Victor


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5929 replies
  • February 9, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/43555#Comment_43555You can't add JS to the survey flow. Add the JS to the header (Look & Feel - General - Header (edit) - <> (source mode)).


Forum|alt.badge.img+1
  • 3 replies
  • February 9, 2022

Thanks a lot for your help TomG :)
Do you also have the JS code regarding the progress? (By progress I mean the time someone spend on the survey).

Thanks by advance,
Victor


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5929 replies
  • February 9, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/43563#Comment_43563The number of seconds someone has spent taking the survey is always stored in the embedded data field Q_TotalDuration.


Forum|alt.badge.img+1
  • 3 replies
  • February 9, 2022

Thanks for your help and reactivity.

I added the LastQuestion and Progress embedded data in the workflow of my surveys.
I know want to add it in the "respondent journey" in the repertory settings (see picture), but the data do not appear... Do you know why?
image.pngThanks again by advance,
Victor


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5929 replies
  • February 9, 2022

Forum|alt.badge.img
  • 1 reply
  • December 15, 2022

Thank you! This is great!
Can it be done to give the user friendly question name instead of the QID?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5929 replies
  • December 15, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/53264#Comment_53264Not easily. The only way to get the question label to to turn on question numbers. Then you have to hide the question numbers and extract the last question number from the question html.
You should vote for this product idea.


Forum|alt.badge.img+4
  • Level 1 ●
  • 4 replies
  • January 15, 2025

Hoping to resurrect this question to see if there’s a way to get more accurate than “It will save the QID of the last question on the last page where they clicked Next.”

Is there a way to add JS to the question itself that takes that Question’s QID and writes it to an embedded data field?  The intention here is that the “LastQuestion” will constantly be updated to the actual last question they answer, even if they don’t finish that block.

Thanks in advance!


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5929 replies
  • January 15, 2025
Todd_C wrote:

Hoping to resurrect this question to see if there’s a way to get more accurate than “It will save the QID of the last question on the last page where they clicked Next.”

Is there a way to add JS to the question itself that takes that Question’s QID and writes it to an embedded data field?  The intention here is that the “LastQuestion” will constantly be updated to the actual last question they answer, even if they don’t finish that block.

Thanks in advance!

It’s not possible because nothing gets saved to the response data on the server until the Next button is clicked (i.e., the updated embedded data is only updated locally on the browser until the Next button is clicked).

One very limiting solution is to have one question per page with auto advance turned on.

 


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2028 replies
  • January 15, 2025
Todd_C wrote:

 Hoping to resurrect this question to see if there’s a way to get more accurate than “It will save the QID of the last question on the last page where they clicked Next.”

Is there a way to add JS to the question itself that takes that Question’s QID and writes it to an embedded data field?  The intention here is that the “LastQuestion” will constantly be updated to the actual last question they answer, even if they don’t finish that block.

Thanks in advance!

You could initiative a webservice call with the state of the page everytime something is clicked. This would get you a more accurate view of where the respondent was, but it isn’t without its drawbacks. 


Forum|alt.badge.img+4
  • Level 1 ●
  • 4 replies
  • January 16, 2025

Thank you, both, for the fast response!  I’m thinking this should be something Qualtrics should solve for everyone, then.  I know most other survey providers can provide this type of information. 

I appreciate your help!


Forum|alt.badge.img+5
  • QPN Level 2 ●●
  • 19 replies
  • March 31, 2025

Has anyone been able to update this code to capture the last question to make it work with the Simple Layout? The code no longer works after switching to this layout type.


Leave a Reply