OpenFn / lwala

2 stars 3 forks source link

New function to map 'undefined' if value is "" [empty string] #75

Closed ritazagoni closed 2 years ago

ritazagoni commented 2 years ago

Background

Lwala wants to update Salesforce cases based on CommCare data. In some instances, CommCare sends us empty strings (when no data is available for a field), but there are values already available in Salesforce. Lwala doesn't want to overwrite those Salesforce values with empty strings.

In case the value from CommCare is an empty string, we want to map 'undefined' to SF (which won't overwrite existing data). To achieve this, we could use a helper function like such:

state.undefinedForEmpty = function (state, choice) {
    if (choice === "") {
     return undefined;
    }
    else {
      return choice;
    }
  };

However, with this solution we would need update every step of mapping in the job, which currently looks like this: field('Birth_Certificate__c',dataValue('properties.birth_certificate'))

to use the helper function, which would look like this:

field('Birth_Certificate__c', state => {
          var choice = dataValue(
            'properties.birth_certificate'
          )(state);
          return state.undefinedForEmpty(state, choice);
        }),

The request

  1. Would there be an easier (one-liner) way to call the helper function for every mapping in the job? (i.e., check all CommCare dataValue mappings - and if empty string found, convert to undefined value` before sending to Salesforce)
  2. If not, we would like to request a new dataValueUndefined() function in language-salesforce which returns undefined in case the source data value is "".
  3. AND/OR.... as we see this requirement as possibly reoccurring in the future, we'd like to propose the new dataValueUndefined function to be added to language-common as well.

The current job

https://github.com/OpenFn/lwala/blob/master/commcare-salesforce-jobs/test_jobs/TEST-Upsert-Person-Case-Update.js

State

Sample data: https://github.com/OpenFn/lwala/blob/master/sample_data/upsert-person-case-update-sample.json (This sample has the example value of Birth_Certificate__c' filled in Salesforce, while the value from CommCare is "" ).

Config

See LP Lwala Salesfoce Sandbox (MOTG - Implementation user)

Adaptor

language-salesforce

aleksa-krolls commented 2 years ago

@taylordowns2000 this is ready to pick up. Please connect with @ritazagoni to evaluate whether this is worthy as a language-pack helper function.

taylordowns2000 commented 2 years ago

@ritazagoni , @aleksa-krolls , I think this is sorted — see Slack thread and note the new adaptor version required when it's released. (I'll update the thread there.) My work is currently on 75_empty_strings and I'm opening a PR shortly.