Upload participants via CSV -> set fields for duplicate filter #603
Replies: 2 comments 4 replies
-
Hey @MatthiasGer0821! AFAICT there's no way to setup the filter fields for deduplicating participants using participants = [
{
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"token": "1",
},
{
"email": "[email protected]",
"firstname": "Jane",
"lastname": "Doe",
"token": "2",
},
{
"email": "[email protected]",
"firstname": "Jane",
"lastname": "Doe",
"token": "2",
},
]
added = client.add_participants(survey_id, participants)
added[-1]['errors'] # {'token': ['Access code "2" has already been taken.']}
len(client.list_participants(survey_id)) # 2 Under the hood, the Web UI inserts the records one by one but does a check for duplicates before adding a new token: if ($bFilterDuplicateToken) {
$aParams = array();
$oCriteria = new CDbCriteria();
$oCriteria->condition = "";
foreach ($aFilterDuplicateFields as $field) {
if (isset($aWriteArray[$field])) {
$oCriteria->addCondition("{$field} = :{$field}");
$aParams[":{$field}"] = $aWriteArray[$field];
}
}
if (!empty($aParams)) {
$oCriteria->params = $aParams;
}
$dupresult = TokenDynamic::model($iSurveyId)->count($oCriteria);
if ($dupresult > 0) {
$bDuplicateFound = true;
$aDuplicateList[] = sprintf(gT("Line %s : %s %s (%s)"), $iRecordCount, $aWriteArray['firstname'], $aWriteArray['lastname'], $aWriteArray['email']);
}
} That dedup could replicated in Python code for dedup_fields = ["lastname"]
participants = [...]
unique = set()
dedup = []
for p in participants:
key = tuple(p[f] for f in dedup_fields)
if key not in unique:
unique.add(key)
dedup.append(p)
added = client.add_participants(survey_id, dedup) |
Beta Was this translation helpful? Give feedback.
-
P.S. Just to put this in other words: The API seems to have deduplication ON by default (using the fields first name, last name, email and token). But what I want is deduplication JUST by token (the equivalent in the WebUI to DISABLE the check for duplicates). I hope this better explained. |
Beta Was this translation helpful? Give feedback.
-
hi @edgarrmondragon
I was wondering if you are aware of how to specify the fields, new participants are filtered by, when uploaded via CSV over the API,
or how to disable that new participants are filtered.
In the webclient, the user can choose if duplicates are filtered (although the token field is always filtered),
and if so, which fields (firstname, lastname, email, attributes).
Is there any way with citric to have this functionality? Or if not, do you maybe have a suggestion of how to go about it?
Best regards!
Matt
Background to my problem: i´m trying to import two participants with different tokens to the same survey.
It´s the same participant (defined by firstname, lastname and email) because it is a parent with two kids.
For each kid, the parent receives a specific token, but firstname, lastname and email are identical.
This use case works via the web interface.
Beta Was this translation helpful? Give feedback.
All reactions