Skip to content

Survey Data

Survey Data is of a userdefined type (de.aristaflow.adept2.model.datamanagement.UDTValue) with the name application/json generated by the survey environment. It is comparable to a BLOB in a database which we cannot interpret and so assume it's a UTF-8 string as byte heaps.

The data format of the survey data can be examined more closely via the process visualisation as follows and can be extracted to a file. The survey data looks like a JsonArray but it is not of the type org.json.JSONObject, nor can it be treated directly like a JsonObject.

Access to certain Survey Data values

As already mentioned in the chapter Parameterhandling, survey data contains all data from a survey form and can be an input or output parameter of a survey activity. However, if you do not want to read or write the entire survey, but only individual values from the Survey Data, we need certain intermediate steps. The Survey Data is of type application/json and this is a user-defined type (UDT). Since UDTs can contain anything, they are treated as black boxes and provided by InputStreams. To get the value of the Survey Data as an InputStream, use the interface getValueAsStream(). To get the value as a byte array, use getValueAsArray(). Individual survey data values ​​can be accessed in a script activity using these methods.

The following examples shows how to access each item of survey data in the Scripting activity. Firstly you have to get the value of the survey data as string and then convert it into JsonObject. The method getValueAsStream() returns the UDT value as InputStream and getValueAsArray() as byte Array byte[]. The method getText() converts the InputStream to string. To parse this value in a JSONObject in Groovy use the JsonSlurper (groovy.json.JsonSlurper) and then the method parseText(). For Rhino take the JavaScript function JSON.parse(value). Finally you have a data structure that can accessed via dot notation. For example you can access an Address field from survey data in Grooy or in Rhino as follows:

  • Groovy
        def slurper = new groovy.json.JsonSlurper();
        def convertedSurveyData = $surveyData.getValueAsStream().getText();
        $Adress = slurper.parseText(convertedSurveyData).Adress;
        
  • Rhino
        var javaString = new java.lang.String($surveyData.getValueAsArray(), "utf-8");
        var jsonObject = JSON.parse(javaString);
        $Adress = jsonObject.Adress;