Javascript Skipped | XM Community
Skip to main content
Question

Javascript Skipped

  • December 1, 2023
  • 2 replies
  • 23 views

Forum|alt.badge.img+5
  • QPN Level 2 ●●
  • 30 replies

Good morning,

in the survey I have configured there are two date values linked together. One of them in fact is calculated by javascript based on the other date (it goes back a few days).
The mechanism is active on several surveys and works fine, the reported problem is that in 2 responses out of hundreds of thousands, the javascript was not read. How is this possible? Could it be that the respondent's browser is unable to read the inserted javascript?

Best,

 

Carlo

2 replies

vgayraud
QPN Level 6 ●●●●●●
Forum|alt.badge.img+58
  • QPN Level 6 ●●●●●●
  • 552 replies
  • December 1, 2023

Hi,

Can you share your script and the date/time when the errors occured?


Forum|alt.badge.img+5
  • Author
  • QPN Level 2 ●●
  • 30 replies
  • December 1, 2023

Yes, the script is this one

 

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{
   var data_ini = Qualtrics.SurveyEngine.getEmbeddedData("DT_ESTRAZIONE_21");
    //var data_ini = "10/12/2023"
    var data_ini1 = data_ini; 
    const myArray = data_ini.split("/");
    var data_ini = myArray[1]+"/"+myArray[0]+"/"+myArray[2];
  console.log("Data iniziale: "+data_ini); //04/07/2023 4 luglio 2023 martedì

function getPreviousDay(date = new Date()) {
  const previous = new Date(date.getTime());
  previous.setDate(date.getDate() - 1);

  return previous;
}

const d = getPreviousDay(new Date(data_ini));
d.setHours(10, 0, 0, 0);
console.log(d);
Qualtrics.SurveyEngine.setEmbeddedData("DT_ESTRAZIONE_21",data_ini1);
Qualtrics.SurveyEngine.setEmbeddedData("DT_COMPETENZA",d);
});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/

});

and the skipped date (DT_COMPETENZA) is this:

 


Best,

Carlo​​​​​​​