OpenFn / grassroot-soccer

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

Make field multi-picklist on `Upsert Risk & Vulnerability Assessment | Service Referral` job #31

Closed daissatou2 closed 2 years ago

daissatou2 commented 2 years ago

Describe the bug

This job is currently failing when multiple options are chosen for the form.risk_assessment.gender_based_violence.abuse_experienced field in state. Because this is a multi-picklist field, when multiple options are chosen in CommCare, the options are separated by a space in state. For example, in this state, form.risk_assessment.gender_based_violence.abuse_experienced equals physical emotional. The run is failing because instead of selecting both Physical & Emotional in Salesforce, it is attempting to select Physical emotional which doesn't exist.

Please update the job to separate the options in this field by space.

To Reproduce

  1. Here is a link to a failed run on OpenFn.org which is indicative of the bug: https://www.openfn.org/projects/pd3yk4/runs/r89rz8eb

expression.js

Link to the job itself in Github: https://github.com/OpenFn/grassroot-soccer/blob/master/jobs/upsertRiskVulnerabilityNewReferrals.js

state.json

https://www.openfn.org/projects/pd3yk4/messages/mdbkjvwv

To test/resolve

  1. After the desired output is working locally (from the CLI), please [push commits to master || open a pull request].
  2. [Please test the change on OpenFn.org by re-running this run (https://www.openfn.org/projects/pd3yk4/messages/mdbkjvwv) and confirming success.]
lakhassane commented 2 years ago

@daissatou2 I made the change but it is failing for the same reason: https://www.openfn.org/projects/pd3yk4/runs/r3xky693

Are those valid values for SF?

lakhassane commented 2 years ago

@chaiwa-berian we might need your input on something you worked on months ago :D

I'm seeing your function checked here https://github.com/OpenFn/grassroot-soccer/blob/master/jobs/upsertRiskVulnerabilityNewReferrals.js#L3-L6

Do you remember where key in that function is from. Here is an example of how that function is used in the code: https://github.com/OpenFn/grassroot-soccer/blob/master/jobs/upsertRiskVulnerabilityNewReferrals.js#L304-L309

chaiwa-berian commented 2 years ago

@lakhassane The keys were from the sample data that @daissatou2 had shared with me. But here is how it works: If the data coming from CommCare is space separated and their corresponding fields in Salesforce are Checkboxes like:

  1. CommCare
    • Data comes in one space separated field like: {"check_the_services_that_client_was_referred_to": "value1 value2 value3"}
    • But each one of these values in Salesforce is a Checkbox field, so we will map the values(value1, value2, etc) to individual corresponding Checkboxes in Salesforce like below.
  2. Salesforce
    • So for each Salesforce field(as specified by @daissatou2 ) we lookup its corresponding value in the CommCare data. So the value we are looking for will act as a key, and if found then we know this Salesforce checkbox is checked or ticked. Again you have to confirm with @daissatou2 to give you the exact mappings(CommCare to Salesforce). The mappings looked something like value1 => ART_Initiation_GRS_Staff__c, value2 => Salesforce_Field_B, etc
    • So the checked helper function would then be passed, value1, for example, and the data from CommCare(in this case dataValue("check_the_services_that_client_was_referred_to")) then it will return false or true, for ART_Initiation_GRS_Staff__c.
    • So when Salesforce receives a true value for Checkbox, it will mark/check/tick the ART_Initiation_GRS_Staff__c field or otherwise.
    • We repeated the same steps for each of the values which would potentially come as part of the check_the_services_that_client_was_referred_to from CommCare, converting the value to boolean and then map to a corresponding field in Salesforce.

Again, once you confirm with @daissatou2 the mappings and share what you are trying to achieve, then we can figure out whether we need to use checked or some other helper transform! Thanks.

daissatou2 commented 2 years ago

Thanks Chaiwa! CommCare is sending all the options that were selected for a multi-picklist question in one field and separating them by spaces. We have to parse that, splitting on the space, and then check/tick each separate answer choice from the state in Salesforce. So for the message above, we need to tick both Physical & Emotional in Salesforce.

image

daissatou2 commented 2 years ago

@lakhassane looks like we have docs on this: https://docs.openfn.org/documentation/apps/salesforce/#picklist-fields

lakhassane commented 2 years ago

@daissatou2 green check right away :D https://www.openfn.org/projects/pd3yk4/runs/rwax5mkx

@chaiwa-berian great thanks for your help here