To remove Agency User Map --> replace with new Province User Map. The new requirement is we want to assign the owned_by user based on the case's current location.
To implement:
Preserve the logic where we first check if this case has an external_id. If yes, return null. If not, proceed to step 2.
owned_by: oscarValue(c.external_id) ? null : provinceMap
Identify the province location code (2 digits).
First determine location based on c.location_current_village_code. Use the first 2 digits to determine the province code (e.g., if location is 12345201 then province code = 12).
If not defined, check organization_address_code (new field added to API response) to determine the province code.
If both are not defined --> do not upload the case to Primero and log that this didn't sync (to discuss).
Use this Province User Map to assign the appropriate owned_by user based on the province code determined above.
https://github.com/OpenFn/unicef-cambodia/blob/96318275dbe2b0abaa175bfef28529caf9ad3b02/jobs/f2-j2-upsertCasesToPrimero.js#L417-L419
To remove Agency User Map --> replace with new Province User Map. The new requirement is we want to assign the
owned_by
user based on the case's current location.To implement:
Preserve the logic where we first check if this case has an
external_id
. If yes, return null. If not, proceed to step 2.owned_by: oscarValue(c.external_id) ? null : provinceMap
Identify the province location code (2 digits).
c.location_current_village_code
. Use the first 2 digits to determine the province code (e.g., if location is12345201
then province code =12
).organization_address_code
(new field added to API response) to determine the province code.Use this Province User Map to assign the appropriate
owned_by
user based on the province code determined above.