Consolidating by removing blank embedded data fields

LarryKaplan
LarryKaplan Boston, MA, USACommunity Member Qubie ✭
edited August 4 in Custom Code

I have 15 embedded data fields filled from five different questions. Some fields could be empty. All I want to do is consolidate the list by removing any empty fields. I'm new to Javascript so my brute force method was to load the embedded data fields into an array. Use the splice method to remove any empty elements, clear the original embedded data fields and then reload them from the array.

The purpose of doing this is so that I can simply pipe in the embedded data in order, and there won't be any awkward spaces.

I'm getting the syntax error, "Invalid JavaScript! You cannot save until you fix all errors: Unexpected token ILLEGAL"

What comma or semicolon have I forgotten?

Here's the code

Qualtrics.SurveyEngine.addOnReady(function () {

               let SemiList =   [Qualtrics.SurveyEngine.getEmbeddedData('Group1a'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group1b'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group1c'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group2a'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group2b'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group2c'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group3a'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group3b'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group3c'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group4a'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group4b'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group4c'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group5a'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group5b'),

                                               Qualtrics.SurveyEngine.setEmbeddedData('Group5c')];

 

               for (let i = 0; i < 15; i++) {

                     if (SemiList[i]===””) {

                             SemiList.splice(i,1);

                     };

             }

               Qualtrics.SurveyEngine.setEmbeddedData('Group1a', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group1b', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group1c', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group2a', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group2b', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group2c', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group3a', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group3b', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group3c', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group4a', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group4b', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group4c', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group5a', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group5b', "");

               Qualtrics.SurveyEngine.setEmbeddedData('Group5c', "");

 

               Qualtrics.SurveyEngine.setEmbeddedData('Group1a', SemiList[0]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group1b', SemiList[1]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group1c', SemiList[2]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group2a', SemiList[3]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group2b', SemiList[4]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group2c', SemiList[5]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group3a', SemiList[6]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group3b', SemiList[7]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group3c', SemiList[8]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group4a', SemiList[9]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group4b', SemiList[10]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group4c', SemiList[11]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group5a', SemiList[12]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group5b', SemiList[13]);

               Qualtrics.SurveyEngine.setEmbeddedData('Group5c', SemiList[14]);

 

});

Answers

  • ahmedA
    ahmedA IndiaCommunity Member, XMPN Member Wizard ✭✭✭✭✭

    You don't need JS for this. Just merge them in the data and analysis tab or towards the end of your survey by creating a new field.

    Alternatively, since you are putting respondents in different groups, do you really need different fields or would one suffice?