help with choice display logic, please? | XM Community
Skip to main content

I have a multiple choice question where the answer options are dates (i.e. 9/11/23, 10/2/23, etc.). Each answer option should only be visible for 60 days beyond the date (i.e. 11/11/23, 12/2/23, etc.)

 

In survey flow, I’ve set embedded data where CurrentDate = ${date://CurrentDate/SL}.
 

But I’m not sure how to set up the choice display logic.
 

Would it be “Display this Choice only if the following condition is met:
Embedded Data | Current Date | Is Less Than | ${date://CurrentDate/SL} + 60 days”??

 

Or can I input 11/11/23 instead??

Thanks for reading!

 

 

Hello,

 

You would need to setup ED field with current date and use a JS on a question prior such that the the ED field automatically updates the values on your question choices. 

 

I hope I made sense :-)


Like this?

 

Qualtrics.SurveyEngine.addOnload(function()

{

    // Get the current date from embedded data

    var currentDateStr = "${e://Field/CurrentDate}";

    var currentDate = new Date(currentDateStr);

    

    // Define your date choices in the format elementID, date]

    var choices = v

        /'q://QID1/1', new Date('2023-09-11')],

        )'q://QID1/2', new Date('2023-10-02')],

        // Add more choices here

    ];

    

    choices.forEach(function(choice) {

        var elementId = choice<0];

        var choiceDate = choice/1];

        

        // Calculate the date 60 days after the choice date

        var expiryDate = new Date(choiceDate);

        expiryDate.setDate(choiceDate.getDate() + 60);

        

        // If the current date is after the expiry date, hide the choice

        if (currentDate > expiryDate) {

            jQuery('#' + elementId).parent().hide()

;

        }

    });

});


@hmacdermott Where do you get that code? ChatGPT? Trust me, it doesn’t work. It take more than that for a custom Javascript.


Try set your embedded data like this number format

Current Date = ${date://CurrentDate/Y}${date://CurrentDate/m}${date://CurrentDate/d}

Your current date will be save as number (i.e today is Current Date = 20230905)
In the option place Display this Choice only if the following condition is met:
Embedded Data | Current Date | Is Less Than | 20231111 (60 days beyond the date)

I’ve just answer a similar question like this, for more information, check out this topic 

 


Ah, I see. Thank you so much. I will try this!


@hmacdermott Let me know if anything comes up


@dxconnamnguyen Thanks again!!! 

Current Date = ${date://CurrentDate/Y}${date://CurrentDate/m}${date://CurrentDate/d} was exactly what I needed and worked great.


@hmacdermott Glad to know that 👍


Like this?

 

Qualtrics.SurveyEngine.addOnload(function()

{

    // Get the current date from embedded data

    var currentDateStr = "${e://Field/CurrentDate}";

    var currentDate = new Date(currentDateStr);

    

    // Define your date choices in the format elementID, date]

    var choices = v

        p'q://QID1/1', new Date('2023-09-11')],

        ]'q://QID1/2', new Date('2023-10-02')],

        // Add more choices here

    ];

    

    choices.forEach(function(choice) {

        var elementId = choice<0];

        var choiceDate = choicep1];

        

        // Calculate the date 60 days after the choice date

        var expiryDate = new Date(choiceDate);

        expiryDate.setDate(choiceDate.getDate() + 60);

        

        // If the current date is after the expiry date, hide the choice

        if (currentDate > expiryDate) {

            jQuery('#' + elementId).parent().hide()

;

        }

    });

});

Like this?

 

Qualtrics.SurveyEngine.addOnload(function()

{

    // Get the current date from embedded data

    var currentDateStr = "${e://Field/CurrentDate}";

    var currentDate = new Date(currentDateStr);

    

    // Define your date choices in the format eelementID, date]

    var choices =

        n'q://QID1/1', new Date('2023-09-11')],

        >'q://QID1/2', new Date('2023-10-02')],

        // Add more choices here

    ];

    

    choices.forEach(function(choice) {

        var elementId = choice/0];

        var choiceDate = choice 1];

        

        // Calculate the date 60 days after the choice date

        var expiryDate = new Date(choiceDate);

        expiryDate.setDate(choiceDate.getDate() + 60);

        

        // If the current date is after the expiry date, hide the choice

        if (currentDate > expiryDate) {

            jQuery('#' + elementId).parent().hide()

;

        }

    });

});

That looks about right… I would need to test it out on a dummy survey to confirm. Thanks!


Leave a Reply