Closed aleksa-krolls closed 2 years ago
@elias-ba can you please prioritize this issue today? I will be online midday to check-in on any questions you might have. Thank you!
@aleksa-krolls I am a little bit confused by the structure of this data file https://github.com/OpenFn/lwala/blob/master/sample_data/taskUpdateCase_Malaria.json. Shouldn't it contain arrays of cases ? What's exactly a case in here ? The properties object ? a mix of the properties and some other values like the case_id ? I am using the mapping sheet but it's huge and I wanna make sure I am not misunderstanding the content of the data file. Could you help clarify this for me whenever you have the chance to be online ?
I also see things like this hardcode default value - see comments
in the mapping and I don't quite understand what they mean. Does it mean that I should consider that this value doesn't exist in the data and that I should hard code it ? or does it mean that the field name is RecordTypeID
but may not be present every time in the data.
Hey @aleksa-krolls we're done implement this. Here is a link to the expression file: https://github.com/OpenFn/lwala/blob/master/commcare-salesforce-jobs/Upsert_Service.js. We didn't create the job in platform cause we do not have information on what the trigger is. Please test it and let us know if there's any feed-back. cc: @taylordowns2000
@elias-ba This job has been working well, but one change request has surfaced.
It turns out CommCare will send us 2 kinds of state.data.indices.parent.case_type
Messages:
"state.data.indices.parent.case_type": "Person"
: https://www.openfn.org/projects/lwala-chw-support/messages/061c5d9e-dae5-7f2a-af03-a953a8072992"state.data.indices.parent.case_type": "Case"
: https://www.openfn.org/projects/lwala-chw-support/messages/061d4b13-549a-7310-9721-966750fa8961If (1) "Person" case_type, then...
Person__r
relationship mapping on L33 should be ADDED to the Service mapping object before upserting in SF to link the Service to the parent PersonParent_Service__r
relationship mapping on L38 should be REMOVED to the Service mapping object before upserting in SF (we do not want to populate this field in SF in this scenario because this Service relates only to a Person, not another Service)If (2) "Case" case_type, then...
Parent_Service__r
relationship mapping on L38 should be ADDED to the Service mapping object before upserting in SF (indices.parent.case_id
is the id of the related Service record in SF)Person__r
relationship mapping on L33 by querying for the Person Id using a Salesforce SQL query...
`SELECT Person__r.CommCare_ID__c FROM Service__c WHERE Service_UID__c = ${state.data.indices.parent.case_id}`
This^ will return a CommCare_ID__c
for Person to use in the L33 mapping.
Other than these 2 parent.case_type differences
, all of the other mappings are the same... so I'm not sure if it makes to have a different upsertIf(...)
operation for each type, or if there is a way we can make only these 2 mappings dynamic.
cc @taylordowns2000
For this sample "state.data.indices.parent.case_type": "Person"
: https://www.openfn.org/projects/lwala-chw-support/messages/061c5d9e-dae5-7f2a-af03-a953a8072992
... the mappings should look as follows:
relationship(
"Person__r",
"CommCare_ID__c",
dataValue("indices.parent.case_id")
),
//NO mapping for Parent_Service__r
For this sample "state.data.indices.parent.case_type": "Case"
: https://www.openfn.org/projects/lwala-chw-support/messages/061d4b13-549a-7310-9721-966750fa8961
... the mappings should look as follows:
relationship(
"Parent_Service__r", //here we map this field
"Service_UID__c",
dataValue("indices.parent.case_id")
),
relationship(
"Person__r",
"CommCare_ID__c",
{response CommCare_ID__c from SF select query - see point 2 above}
)
@aleksa-krolls do you have any idea about this error ? INVALID_FIELD: Foreign key external ID: a030800001zr4hq not found for field CommCare_ID__c in entity Person__c
. It seems like the value a030Q000008XyXV
doesn't exist.
@elias-ba when sharing an error, please confirm which state you are using to test because I'm not sure how you got that error mentioned in your comment... to avoid such an error I had already hardcoded an ID in Line 26 for sandbox testing.
As I commented on Slack- I added the missing person to the sandbox, can you please proceed with the changes? Fyi, you will continue to hit the error in this until you implemented the change I requested: https://www.openfn.org/projects/lwala-chw-support/runs/061d8512-f78e-7c81-b159-e603d6f07577
@elias-ba see above for my comment from last week, and lmk if you have more questions or if a quick call would help ... would be great to start testing this morning.
@taylordowns2000 I've just ran a test, and it's failing when form.indices.parent.case_type === "Case"
.
https://www.openfn.org/projects/lwala-chw-support/runs/061dc0ee-478a-7b00-9e77-524777293d91
See L14 in run log where the CommCare_ID__c
is undefined
even though a record was found in the SOQL query. Can you take a look?
Background
Lwala CHWs collect data in CommCare and want to sync these with Salesforce for reporting across CHW areas. When CHWs visit Households, they will register a new "case" if the person needs a referral or follow-up. These cases should be registered in Salesforce as
Service__c
records, which link to the relatedPerson__c
(parent table in SF) visited.Request
Upsert 1
Service__c
record in Salesforce for each Message (aka case update) received from CommCare.See OpenFn Map tab for mapping specifications.
adaptor
salesforce
expression
New
Upsert_Service.js
jobstate
configuration: See LP for
Lwala Salesforce Sandbox MOTG (Dec 21)
data: https://github.com/OpenFn/lwala/blob/master/sample_data/taskUpdateCase_Malaria.jsonTesting Notes
Feel free to create data in the Sandbox as you wish. Successful run of this message should create 1 new Service.