GetRespondents
Description
Gets a DataSet with a DataTable that is populated according to the filter (respondentTransferDef), with respondents.
Signature
DataSet GetRespondents(string key, RespondentTransferDef respondentTransferDef)
Parameters
Name | Data Type | Description |
---|---|---|
key |
string required |
The authentication key |
respondentTransferDef |
RespondentTransferDef required |
The transfer definition object. |
Example
//***************************************************
//
// GetRespondents
// UpdateRespondents
//
//***************************************************
// Array of error-objects that will be returned if errors
// in a UpdateRespondents()-function
ErrorMessage[] errors;
// We will use ds and dt when retrieving respondents
DataSet ds;
DataTable dt;
// New instance of the SurveyData webservice
SurveyDataSoapClient sd = new SurveyDataSoapClient();
// We make the assumption that we have a project with
// the backgroundvariables 'gender' (precodes F and M),
// age (integer) and email (string).
// Get empty DataTable
ds = sd.GetRespondents(key,
SurveyDataUtil.NewRespondentTransferDef(
true,true,projectID));
dt = ds.Tables[SurveyDataUtil.RespondentTableName];
// Add a new column
// (If 'email' is needed and not already specified as a backgroundvariable
// in the survey the column should be added to enable email sendout)
// In this example we assume that 'email' is already a background variable.
string newColumnName = "myNewColumn";
if (!dt.Columns.Contains(newColumnName))
{
dt.Columns.Add(
new DataColumn(newColumnName,typeof(string)));
}
// Add a new row
DataRow dr = dt.NewRow();
dr["gender"] = "F";
dr["age"] = 17;
dr[newColumnName] = "my new value";
dr["email"] = "dummy@dummy.com";
dt.Rows.Add(dr);
// Make the update
errors = sd.UpdateRespondents(key,projectID,ds,true,false,"",false,-1);
// Check if there was any errors
if (errors.Length>0)
{
//Implement error-handling here
}
// Make a definition that limits to retrieve the user columns 'email'
// and the new column defined by the variable newColumnName
// and the system columns 'respid' and SID from all female respondents (gender=F)
RespondentTransferDef def =
SurveyDataUtil.NewRespondentTransferDef(
false,false,projectID);
ArrayList fieldNames = new ArrayList();
fieldNames.Add("email");
fieldNames.Add(newColumnName);
def.FieldNames = (string[])fieldNames.ToArray(typeof(string));
RespondentSystemVariables s = new RespondentSystemVariables();
s.IncludeRespId = true;
s.IncludeSID = true;
def.SystemVariables = s;
def.Where = SurveyDataUtil.NewWhereClause(
SurveyDataUtil.NewBinaryComparison(
ComparisonType.Equal,
SurveyDataUtil.NewQueryField("gender"),
SurveyDataUtil.NewQueryConstant(ConfirmitDbType.VarChar,"F")));
// Read the specified respondents
ds = sd.GetRespondents(key,def);
dt = ds.Tables[SurveyDataUtil.RespondentTableName];
// Change the new column for the retrieved rows
foreach (DataRow drResp in dt.Rows)
drResp[newColumnName] = "My female comment";
// Make the update
// Note that we needed to retrieve the 'respid' to be able to update
errors = sd.UpdateRespondents(key,projectID,ds,true,true,"",false,-1);
// Check if there was any errors
if (errors.Length>0)
{
//Implement error-handling here
}