Closed daissatou2 closed 2 years ago
@daissatou2 I have a question here.
When upserting multiple (let's say 2) attendances do we map the, same value for all the fields except coach_name
?
Here is the mapping. The only changing value here is coach_name (Person_Attendance__r
). Is that right?
fields(
relationship('RecordType', 'Name', 'Intervention (Staff)'),
relationship('Event__r', 'CommCare_Case_ID__c', dataValue('form.case.@case_id')),
relationship('Person_Attendance__r', 'CommCare_Ext_ID__c', state => {
const coach_name = dataValue('form.coach_name')(state)
? dataValue('form.coach_name')(state)
: state.references[0].records[0].Coach_A__r
? state.references[0].records[0].Coach_A__r.CommCare_Ext_ID__c
: '';
return coach_name;
}),
field('CommCare_Ext_ID__c', dataValue('commcare_external_id'))
),
Yes this looks good to me @lakhassane
@daissatou2 feel free to test in this
@daissatou2 Let's get this out of backlog... please test, close this issue, and reprocess any failures.
@lakhassane this is still failing with a new error: https://www.openfn.org/projects/pd3yk4/runs/0618b969-1f8e-733c-8cee-0cf43982a5ae
@daissatou2 this is fixed: https://www.openfn.org/projects/pd3yk4/runs/0618cf90-4c58-7c26-84c7-712f55e63b70
Some of the data we needed for upsert were being crashed inside the each()
Background, context, and business value
The
Coach Session Register
job currently assumes that only 1 coach can be sent in the message so it's only upserting 1 Coach's attendance record. Let's update this job to recognize when more than one coach is sent.The specific request, in as few words as possible
We are getting the
CommCare_Ext_ID__c
for each coach's Attendance record using theform.coach_name
field in state. We know that there is more than one coach if there are spaces in the string.Ex. 1 coach: a0f0ffd71dbd43b882788bf68712368d 2 coaches: a0f0ffd71dbd43b882788bf68712368d c0bb90db26224656b4431c5afb2ea0f4 3 coaches: a0f0ffd71dbd43b882788bf68712368d c0bb90db26224656b4431c5afb2ea0f4 c0bb90db26224656b4431c5afb2e3878
Update this job to split coach name on the space and upsert as many Attendance records as there are coaches. (Let's assume the maximum number of coaches is 3). For all fields related to the coach in Salesforce we currently have
Coach_A__c)
. For coaches 2 and 3, this will beCoach_B__c
&Coach_C__c
respectively.state.json
LP:
GRS Salesforce Production
State with two coaches: https://www.openfn.org/projects/pd3yk4/messages/06168780-51e0-70b7-a9d7-b36d88adac1a Failed run: https://www.openfn.org/projects/pd3yk4/runs/0616ee8e-487b-73b2-884c-cc653ce1f810expression.js
If no space in
form.coach_name
, upsert 1 attendance record. For every space inform.coach_name
upsert an additional attendance record for that coach. Let's assume 3 is the maximum.