OpenFn / lwala

2 stars 3 forks source link

Modify job to mass update CommCare cases #53

Closed aleksa-krolls closed 3 years ago

aleksa-krolls commented 3 years ago

Background

Lwala is using Salesforce to auto-generated Household codes it assigns to each new record. We want OpenFn to sync this Household Code back to CommCare to overwrite the CommCare case name to match this code.

Request

I've already draft a job that does this using the CommCare Bulk XLS Import API (see CommCaredocs). However, I need help updating the job to handle 2 different versions of state.

  1. Sometimes Salesforce sends us webhook notifications with the data in an object "Notification": {...} https://www.openfn.org/projects/pdbmj5/messages/06151ffd-989f-76cc-a70d-b4feb3ba5bc3

  2. Sometimes the data comes in an array "Notification": [...]... so we'll probably need to implement each(...) here and build an XLS with several rows to submit to CommCare: https://www.openfn.org/projects/pdbmj5/messages/06151feb-91fa-7972-bc9e-65030bfbde5e

adaptor

commcare see the job on prod: https://www.openfn.org/projects/pdbmj5/jobs/jvendk

expression

https://github.com/OpenFn/lwala/blob/b2e860fc818ba6a2e1dd2b6a8a9cc638f9fb5ce3/salesforce-commcare-jobs/Update-HH-Name.js#L7

state

See LP for OpenFn CommCareHQ (Lwala) See message links above... feel free to test both on prod.

Testing notes

You can validate the success of these imports via this CommCare page: https://www.commcarehq.org/a/lwala-community-alliance/data/edit/import_cases/ For every message sync, you should see that N cases were matched and updated.

aleksa-krolls commented 3 years ago

@taylordowns2000 I think this will be a quick one since I already drafted the job... do you or Elias have time today to help me out to unblock testing? (It can wait until tomorrow, if not... maybe backlog will clear out.)

elias-ba commented 3 years ago

@aleksa-krolls I'd love to help on this. Maybe we can setup some time in the afternoon today to work on this ?

taylordowns2000 commented 3 years ago

@elias-ba , could you go for it now?

i'm tied up until noon BST, but you can spin this up locally and try to solve without making commits to main. @lakhassane could give a quick pointer here and there if necessary

elias-ba commented 3 years ago

Yes @taylordowns2000 I can. I just need 30 minutes to finish my work on #1402 and I jump on this one. @lakhassane (or @aleksa-krolls) do you think you can have 10 minutes to give me more context / Knowledge on this in a quick call ?

elias-ba commented 3 years ago

Hey @aleksa-krolls, this seems to be working fine locally now. In order for it to work we had to modify the language-commcare adapter to see this commit that I made ? We may be blocked because I cannot release a new version of the language-commcare adaptor and @taylordowns2000 and @lakhassane are currently unavailable.

taylordowns2000 commented 3 years ago

@elias-ba , I've released the adaptor version (v1.3.0) and tested this on prod. All green checks, but I do not see the expected results when validating in the CommCare app. image.png Possible that the job code is only accounting for one of the two shapes of data that @aleksa-krolls requires? See my last run for each of these different looking messages:

  1. https://www.openfn.org/projects/pdbmj5/runs/06154101-56d9-7b71-9ad6-effcb0bcce47
  2. https://www.openfn.org/projects/pdbmj5/runs/06154101-07b4-7bb6-b5db-cfd32f962a90
elias-ba commented 3 years ago

Thanks @taylordowns2000. What are these two records at 0705 ?

taylordowns2000 commented 3 years ago

@elias-ba , are you online but not on Slack? Was trying to chat you there before. Please ping me there if you're around and want to work on this.

(The records are the result of the successful runs that I linked to.)

elias-ba commented 3 years ago

Hey @aleksa-krolls this is all-good now. I have tested locally and in prod. Everything works as expected. Can you give it a test and lemme know ?

aleksa-krolls commented 3 years ago

thanks @elias-ba , working well! Will keep you posted if anything else comes up.