Summary
Surveys are series of questionnaires designed to collect various types of data for research or analysis purposes. In ArcGIS Survey123, both qualitative and quantitative data can be collected.
In some cases, some qualitative data, such as the names of weekdays or months, must be recorded in a quantitative manner for data tabulation. This article describes the workflow to convert weekday and month strings to integers in ArcGIS Survey123 Connect. The JavaScript getDay() function is used to convert weekday strings (Monday, Tuesday, Wednesday) to integers (1-7), and the getMonth() function to convert month strings (January, February, March) to integers (1-12).
Procedure
- Log in to ArcGIS Survey123 Connect and create a new survey.
- Click XLSForm to open the survey's XLSForm.
- Create a date question.
- In the type column of the survey worksheet, select date.
- Specify the values in the name and label columns.
- Create a note question. In a new row, in the type column, select note, and configure the name and label columns.
- Create a JavaScript file with a code that converts weekday strings to integers.
- In ArcGIS Survey123 Connect, on the Scripts tab, click New script, name the script file, and click Create.
- Paste the following code into the window. Replace <date_name_field> with the name of the question created in Step 3:
function myfunction(<date_name_field>) {
var dt = new Date(<date_name_field>);
return dt.getDay() + 1
}
-
- Click the Save icon to save the code.
- Click the Select function icon to display the function.
- Click the Copy to clipboard icon to copy the pulldata() function.
- Paste the pulldata() function into the note question created in Step 4.
- In the survey's XLSForm, paste the pulldata() function into the calculation column of the note question.
- Remove any angled brackets from the function.
- Create another note question and a JavaScript file with a code that converts month strings to integers. Repeat Steps 4 through 6 using the following code. Replace <date_name_field> with the name of the question created in Step 3:
function myfunction(<date_name_field>) {
var dt = new Date(<date_name_field>);
return dt.getMonth() + 1
}
The image below shows both functions are pasted into the calculation column of the respective note questions.
- Click Save on the XLSForm and publish the survey.
The image below demonstrates the date conversion. Sunday, the first day of the week, is converted to 1, while July, the seventh month of the year, is converted to 7.