Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Allow passwords only on a specific day of the week

We would like to make passwords to enter the survey valid only on specific days of the week.


Monday: ABC
Tuesday: ABCD
Wednesday: ABCDE

Is there a solution for this or a trick possibly via skip logic?
asked Jul 26, 2021 by Max (180 points)

1 Answer

+1 vote
Best answer
Max, this solution may suit your needs?

Create a survey page at the very front of your survey that is used to store the below Perl Script. Insert this Perl Script in to the footer of this survey page.
[%Begin Unverified Perl
 use POSIX qw(strftime);
 my $DayOfWeekID="";
 $DayOfWeekID=strftime "%w", localtime;
End Unverified%]

This page is not displayed to the respondent. It simply runs the Perl Script. This survey page can be a select question without question script using a constructed list that evaluates to one item. That will certainly work and will never be displayed to the respondent. You can also use a free format hidden question as an alternative.

Now create a pass-in field called "DayID" and define it as a whole number.

So "DayID" saves the day of the week as an integer with Sunday=0, Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5 and Saturday=6.

For every password you import, you can allocate a day of the week that uses the same 0-6 definitions. Assume this is called "SampleDay".

Now you can compare "DayID" (the actual day) with "SampleDay" (the sample day) in skip logic to control the respondents movement.

If DayID=SampleDay, skip to Q1.
answered Jul 26, 2021 by Paul Moon Platinum (98,990 points)
selected Jul 27, 2021 by Max
Thank you for this, it looks great!

For us it would be best if all the password fields could be determined by the respondents themselves, due of the nature of the study.

It would be ideal if we could send a link every day that contains the following fields, without predeterming any passwords:

PASSWORD = abcde & SAMPLEDAY = 1 & DAYID = 99

If we then set the DayID to the current day (0-6) instead of 99 (or any other number) on the hidden question through your Perl script, then we should be able to check in the skip logic whether SAMPLEDAY and DAYID match and then sort out participants?

However, this does not seem to work at the moment, since apparently only the DAYID is checked, which is already in the link and is not overwritten by the current day from the script.
Hi again Max.

You can pass in a DayID via the survey link as you indicated. Ensure it is a whole number given you have defined it as such in your pass-in fields.

And when you pass the DayID in via the survey link, you can change what was passed in to some other value by using SETVALUE using SSI Script or Perl Script.

Also, your Perl Script can contain conditional script to say something like ...

If DayID=99, do "A"
Else do "B"

Here's an example of the earlier script ...
[%Begin Unverified Perl

   use POSIX qw(strftime);
   my $DayOfWeekID="";
   $DayOfWeekID=strftime "%w", localtime;
End Unverified%]

I'm not really sure what you are trying to do. Your latest post had me somewhat confused?

If you could please elaborate a little further, I'll try to assist.

I'm sure a splash of survey links passing in DayID and Perl Script and skip logic should get you sorted out.
Again, thanks for your support!

The issue is that the DayID is not overwritten by the script, so our skip logic (DayID != SampleDay, Terminate) does not work.

Currently the skip logic only works if the DayID in the link exactly matches SampleDay.
I just conducted a test where I passed DayID in as "99" via the survey link, and using SETVALUE, changed DayID to the current day value.
Here is a simple test for you to conduct ...

Pass the DayID in as "99" via the survey link.

Now insert this SSI Script command in to a survey page footer up the front end of the survey ...

Let's see this script change DayID from "99" to "100".

Once you have this working, you know you can change the value of DayID within your survey. Then you can go back to your script to see where things aren't working.

For this to work, the survey page you insert this script on to must not be skipped. You have to give it a chance to evaluate / run.

Are you sure the survey page with Perl Script on it is not skipped?
We have located the issue: The first page after the "hidden" page with the script must not be skipped with a pre-skip.  

Once this was solved, the solution worked, thanks a lot!
Aaaah yes, as I suspected, the page was being skipped.

Well done, glad to see you now have it working.