OpenFn / grassroot-soccer

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

Register Participant values look undefined for name, sex, etc. #5

Closed aleksa-krolls closed 3 years ago

aleksa-krolls commented 3 years ago

Background, context, and business value

See issue #1 for original specs. See this run where First_Name__c, Surname__c, Sex__c and other identifying fields are returning undefined... can you check the job and mappings to verify? https://www.openfn.org/projects/pd3yk4/runs/r7xrk749

expression

https://github.com/OpenFn/grassroot-soccer/blob/master/jobs/2.d.upsertRegisterParticipant.js

state

https://www.openfn.org/projects/pd3yk4/runs/r7xrk749 Please feel free to re-run on prod

aleksa-krolls commented 3 years ago

@chaiwa-berian can you take this on today or Monday?

taylordowns2000 commented 3 years ago

@aleksa-krolls, @daissatou2 , for some messages (https://www.openfn.org/projects/pd3yk4/messages/mk5a66v8 - the message which produced the undefined above) it appears that form.question1 is an array of objects. For other messages (https://www.openfn.org/projects/pd3yk4/messages/mgk5gdvb) and for the mapping provided on the specifications spreadsheet, it's a single object.

Questions from me/ @chaiwa-berian :

  1. What does it mean for question1 to be an array? (I see two different participants in that array.)
  2. What should we do with each item in that array?
  3. Do you expect messages to arrive in both formats going forward, or should we build the job for one of these two shapes of messages.

Array of question1 objects:

image.png

A single question1 object:

image.png

aleksa-krolls commented 3 years ago

@taylordowns2000 @chaiwa-berian Thanks for flagging as we hadn't seen a submission with multiple items in the array yet. It looks like this CommCare form allows users to register 1 or multiple participants. Therefore question1 is like a repeat group, and we should register 1 Participant for each item in the question1:[...].

Can you please adjust the job to handle this potential array of participants accordingly? Thanks! cc @daissatou2

aleksa-krolls commented 3 years ago

@chaiwa-berian please work on this to handle the array. See my comment above.

taylordowns2000 commented 3 years ago

Ah! OK, I think we've seen this before... didn't we "enforceArray" for some other client? Where's the job library when you need it? @aleksa-krolls , @lakhassane , do you remember where we did this before?

lakhassane commented 3 years ago

Yeah we did in some other jobs.

Look for something like

Array.isArray(...)
chaiwa-berian commented 3 years ago

@aleksa-krolls This is fixed, see run here.

aleksa-krolls commented 3 years ago

@chaiwa-berian We had to update the path to @case_id based on state. The job is now failing with a type error? See here: https://www.openfn.org/projects/pd3yk4/runs/rd78rpzp Why? Is it maybe because of the @ character?

State to use: https://www.openfn.org/projects/pd3yk4/messages/mn575657 Expression: jobs/2.d.upsertRegisterParticipant.js

If you have questions, let @daissatou2 know and you all can jump on a call.

chaiwa-berian commented 3 years ago

@aleksa-krolls Yes, the merge is creating another field called case_id which we use in subsequent field operations like here field('Participant_Identification_Number_PID__c', dataValue('case_id')),. So that caused the error.

chaiwa-berian commented 3 years ago

@aleksa-krolls , @daissatou2 and I fixed this!