HOW TO

Convert weekday or month strings to integers using JavaScript functions in ArcGIS Survey123 Connect

Last Published: July 18, 2023

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

  1. Log in to ArcGIS Survey123 Connect and create a new survey.
  2. Click XLSForm The XLSForm icon. to open the survey's XLSForm.
  3. Create a date question.
    1. In the type column of the survey worksheet, select date.
    2. Specify the values in the name and label columns.
  4. Create a note question. In a new row, in the type column, select note, and configure the name and label columns.
The date and note questions added to the XLSForm.
  1. Create a JavaScript file with a code that converts weekday strings to integers.
    1. In ArcGIS Survey123 Connect, on the Scripts The Scripts icon. tab, click New script, name the script file, and click Create.
    2. 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
}
    1. Click the Save icon to save the code.
    2. Click the Select function icon to display the function.
    3. Click the Copy to clipboard icon to copy the pulldata() function.
The code and the function on the Scripts tab.
  1. Paste the pulldata() function into the note question created in Step 4.
    1. In the survey's XLSForm, paste the pulldata() function into the calculation column of the note question.
    2. Remove any angled brackets from the function.
The pulldata() function pasted on the calculate column of the note question.
  1. 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.

The pulldata() function pasted on the calculate column of the second note question.
  1. Click Save The Save icon on the XLSForm. 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.

The survey displays the converted weekday and month strings to integers.

Article ID: 000030838

Software:
  • ArcGIS Survey123 Connect

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options