OpenFn / grassroot-soccer

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

Do not fail jobs if related Participant record not found #38

Closed daissatou2 closed 2 years ago

daissatou2 commented 2 years ago

Background, context, and business value

The GRS team wants us to ignore certain Register Participant forms which are submitted. This is causing other forms which might reference the participant we didn't sync to fail. Let's update the appropriate jobs to not fail these runs but instead log a helpful message.

The specific request, in as few words as possible

At the beginning of each of the jobs below: check if the related Person__c record exists in Salesforce.

SELECT Participant_Identification_Number_PID__c from Person__c where Participant_Identification_Number_PID__c  = {INSERT ID HERE}

Below, I have included the paths for the source field for the Participant_Identification_Number_PID__c to search for the record in SF.

  1. If the Person exists, the job should continue as usual.
  2. If the Person doesn't exist in Salesforce, stop the job and log the message "Participant not found with Participant_Identification_Number_PID__c: [INSERT ID HERE]". This run should still show as successful, but this message should be logged.

I have listed the paths & sample runs for the Participant_Identification_Number_PID__c for each job below. Once you finish, you can rerun each of those messages to ensure they no longer fail.

  1. upsertAttendanceSkillsPlusClub - form.attendance_list.update_participant_cases.item[].@id- failed run
  2. upsertHomeVisitLog - ${form.case['@case_id']} - failed run
  3. upsertPostChallenges - form.case.@case_id - failed run
  4. upsertPreChallenges - form.case.@case_id - failed run

For example, instead of this run failing it should pass and log the message " Participant not found with Participant_Identification_Number_PIDc: [INSERT ID HERE]". Since this is a upsertPostChallenges run, use the value in form.case.@case_id from the message to search in SF if a Person__c record has `Participant_Identification_Number_PIDc` equal to that value.

state.json

{ "configuration": "GRS Salesforce Production", "data": "Run links with messages linked above" }

expression.js

Jobs linked above

aleksa-krolls commented 2 years ago

@daissatou2 fyi, I saw you created this and went ahead and added the Salesforce SOQL query to your request description above. Once you're done drafting this issue, please assign to @lakhassane and @grayey and move to Backlog.

aleksa-krolls commented 2 years ago

@grayey @lakhassane can you two work on this today? Let @daissatou2 know if any questions.

grayey commented 2 years ago

I will arrange with @lakhassane, see if we can today.

lakhassane commented 2 years ago

@daissatou2 we might one question here. For upsertAttendanceSkillsPlusClub the ID path you gave is inside the item array. That mean there is many @id in there. Do you have any information which one should be used in particular because I don't think we must execute the query for all the @id in the item array?

Also, we saw a path to @case_id for that run here: form.case.@case_id. Should we use that one instead of the one you provided?

lakhassane commented 2 years ago

@daissatou2 we made corrections. For job 2, 3 and 4. Find the succesfull runs here.

upsertHomeVisitLog.js => https://www.openfn.org/projects/grs-integrations/runs/062150b0-bbdb-78df-999c-a6c89bb48c8e upsertPostChallenges.js => https://www.openfn.org/projects/grs-integrations/runs/062150a0-0478-7725-bdaa-5f186aee746e upsertPreChallenges.js => https://www.openfn.org/projects/grs-integrations/runs/062150be-5910-702a-8f5b-df4280e2f858

daissatou2 commented 2 years ago

@lakhassane for upsertAttendanceSkillsPlusClub please use the first item in the array

lakhassane commented 2 years ago

@daissatou2 it's done. Fine the run for job 1 here: https://www.openfn.org/projects/grs-integrations/runs/062150f1-a2da-71a4-bc32-af289f21a3a2

daissatou2 commented 2 years ago

@lakhassane @grayey moving this back to backlog, please do the same for the new job below:

upsertAttendanceNonSkillz - form.attendance_list.update_participant_cases.item[].@id - failed run. Please check the first item in the array.

grayey commented 2 years ago

@daissatou2 this is done. Here's a successful run.