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 Survey Data

In order to be able to read or write the value of a user defined data type (UDT) here Survey Data, we have to take intermediate steps. 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(). Or to get it as a byte array, use getValueAsArray().

The following examples show how to access each item of the 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 the method parseText(), for Rhino take the JavaScript function JSON.parse(value). Finally you have a data structure that can accessed via dot notation.

  • 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;
          

Example Survey Data

We can now retrieve and display only specific data from the survey data instead of displaying the entire survey. We'll revisit the previous example [External Survey URI] (../SurveyJS-Creator/#Example-External-Survey-RI) and add another Scripting step between the two survey activities. To do this, we remove the external survey from the second step and adjust the survey in the SurveyJS Creator. We would now only display the Name and Adress and enter the script for Groovy Scripting activity from the previous section. Here we read the survey data from the first step and pass the adress from it to the next step.