OpenFn / grassroot-soccer

Grassroot Soccer CommCare-Salesforce integrations
https://openfn.github.io/grassroot-soccer/
0 stars 0 forks source link

Handle 1 or multiple attendance entries in `upsertAttendance.js` #11

Closed aleksa-krolls closed 3 years ago

aleksa-krolls commented 3 years ago

See issue #9 for a similar fix implemented.

Issue

Job upsertAttendance.js currently fails because it cannot handle an array of multiple Attendance records. If only 1 attendance is entered, CommCare form outputs an object (item: {...}), but outputs an array if there are multiple attendance entries (item: [{...},{...}]). We need to update the job to handle both scenarios.

We tried editing the job to add each(...) but it's now failing with this error: https://www.openfn.org/projects/pd3yk4/runs/rmkw5nwd TypeError [Error]: fields is not iterable (cannot read property Symbol(Symbol.iterator))

Can you please take a look and make sure this job will succeed when Attendance for either 1 or multiple people is submitted?

expression

https://github.com/OpenFn/grassroot-soccer/blob/master/jobs/upsertAttendance.js

state

  1. Submission with 1 Attendance entry: https://www.openfn.org/projects/pd3yk4/messages/mdbqpvpn
  2. Submission with 22 Attendance entries: https://www.openfn.org/projects/pd3yk4/messages/ma9r8p7z

To test, please run these^ on prod to verify the changes you've made.

chaiwa-berian commented 3 years ago

@aleksa-krolls , I have updated the job to handle 1 or multiple attendance entries and I also have some mapping questions added in-line. Let me know if this works after addressing these questions.

aleksa-krolls commented 3 years ago

@chaiwa-berian looks like this version of state (see #1 above) does have intervention_name. Can you please make sure the job works for this state also? https://www.openfn.org/projects/pd3yk4/messages/mdbqpvpn

I'm working on finding a different version of state for #2 where there are multiple attendance entries. In the meantime, pls make sure the CommCare_Ext_ID__c is set correctly and contains no undefined values for the above.

chaiwa-berian commented 3 years ago

@aleksa-krolls This job is now correctly resolving intervention_name but it fails on ids not being found in Person__c and Event__c. Kindly verify we are pointing to the right paths or that the ids exist in Salesforce. See a re-run with this message: https://www.openfn.org/projects/pd3yk4/messages/mdbqpvpn