Select to view content in your preferred language

Control Open/Close Survey Date Range Programmatically

751
4
Jump to solution
11-13-2023 03:57 PM
GregReinecke
Frequent Contributor

Hello,

Every week I'd like to automatically Open a survey on Sunday and Close it on Thursday.  I know I can control the survey based on a specific Date range by interactively opening the Survey123 app but could I reset the  Date range in the survey via Connect or a script or Model Builder?

Thanks,

GR

0 Kudos
2 Solutions

Accepted Solutions
GregReinecke
Frequent Contributor

The Survey123 Connect solution did the trick. I created some Python to run in the windows task scheduler to update the .info file every Sunday. 

But now to complete the challenge I have to publish the survey so the changes to the .info file take effect. Can this be automated?

Thank you so much ZhifangWang! 

View solution in original post

0 Kudos
ZhifangWang
Esri Regular Contributor

Hi @GregReinecke ,

In Survey123 Connect or Survey123 website, publishing a survey actually does two jobs: 1. update the .zip package for the form item, 2. create/maintain the behind feature layer. For your case, only updating the .zip package for the form item needs to be done.

To complete this, you can use Python script to:

1. Download the .zip package file of the form item at /data endpoint.

2. Update the .info file inside the package file.

2. Update the /data of the form item with the updated package file by using the /update item endpoint.

This should save you from publish the survey manually in Survey123 Connect.

View solution in original post

0 Kudos
4 Replies
ZhifangWang
Esri Regular Contributor

Hi @GregReinecke ,

The open/closed setting is saved in the form.json file (settings.openStatusInfo) for a survey published from the Survey123 website or the <surveyName>.info file for a survey published from Survey123 Connect. Technically, you can use a script to update this setting in the file and then update the .zip file at the /data endpoint of the form item.

If your survey was published in Survey123 Connect, another workaround might be utilizing the `format-date(${date1}, '%a')` function to get the day of today. Then set corresponding questions to be always invalid and required or hidden to achieve the goal.

ZhifangWang_0-1700038301305.png

 

0 Kudos
GregReinecke
Frequent Contributor

The Survey123 Connect solution did the trick. I created some Python to run in the windows task scheduler to update the .info file every Sunday. 

But now to complete the challenge I have to publish the survey so the changes to the .info file take effect. Can this be automated?

Thank you so much ZhifangWang! 

0 Kudos
ZhifangWang
Esri Regular Contributor

Hi @GregReinecke ,

In Survey123 Connect or Survey123 website, publishing a survey actually does two jobs: 1. update the .zip package for the form item, 2. create/maintain the behind feature layer. For your case, only updating the .zip package for the form item needs to be done.

To complete this, you can use Python script to:

1. Download the .zip package file of the form item at /data endpoint.

2. Update the .info file inside the package file.

2. Update the /data of the form item with the updated package file by using the /update item endpoint.

This should save you from publish the survey manually in Survey123 Connect.

0 Kudos
GregReinecke
Frequent Contributor

Thank you. This is the kickstart I needed. Plenty of guidance on the web on how to implement your info. Looking forward to working through it. Thanks again @ZhifangWang. 

0 Kudos