OpenFn / lwala

1 stars 3 forks source link

Only insert deceased Person if deaths >0 #17

Closed aleksa-krolls closed 4 years ago

aleksa-krolls commented 4 years ago

https://github.com/OpenFn/lwala/blob/cda5f96c02603c565b85cda65cd23fed14bcb93f/commcare-salesforce-jobs/MOH513-Update-Household-in-SF-Production.js#L58-L108

Need to add a line to only run this part of the job if deaths > 0 (where deaths is the array we defined in alterState). Can you help me out here? Have tried a few variations and can't seem to get it to work :-)

taylordowns2000 commented 4 years ago

Is using upsertIf an option here instead of upsert?

From language Salesforce adapter docs:

/**

On Tue, Apr 14, 2020 at 3:55 PM Aleksa Krolls notifications@github.com wrote:

Assigned #17 https://github.com/OpenFn/lwala/issues/17 to @taylordowns2000 https://github.com/taylordowns2000.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/OpenFn/lwala/issues/17#event-3233050972, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCUBLOCK3ZP7CXYNANNDWTRMTLTVANCNFSM4MICSJTA .

-- Taylor Downs | Head of Product Open Function Group https://www.openfn.org/ | How Data Integration Makes ICT4D Work https://youtu.be/GVB9voGp6T4

aleksa-krolls commented 4 years ago

@taylordowns2000 I'm still struggling to getting upsertIf() to work here and spending way too much time. Can we walk through tomorrow?

I'm finding the upsert always executes even if the logical is false. I'm wondering if it has something to do with this upsertIf being nested under merge()...

If I try this expression but add in upsertIf (see one of many variations I tried below), and run it with this state.json (where "deaths_in_past_6_months" : "0")--> it still upserts a Person record when it should not because logical is false.


  upsertIf(state => {
      var deaths = state.data.form.household_deaths.deaths_in_past_6_months;
      return (deaths > 0 ? true : false);
    },
    "Person__c", "CommCare_ID__c", fields(
taylordowns2000 commented 4 years ago

Maybe a syntax thing? Replace line 68 upsert("Personc", "CommCare_ID__c", fields( with upsertIf((state.data.form.household_deaths.deaths_in_past_6_months > 0), " Personc", "CommCare_IDc", fields( and it should work. I've tested it with FakeAdaptor and the output is "Not upserting Personc because logical is false." Will wait for your confirmation before testing with Adaptor.

Taylor

On Fri, Apr 24, 2020 at 1:20 AM Aleksa Krolls notifications@github.com wrote:

@taylordowns2000 https://github.com/taylordowns2000 I'm still struggling to getting upsertIf() to work here and spending way too much time. Can we walk through tomorrow?

I'm finding the upsert always executes even if the logical is false. I'm wondering if it has something to do with this upsertIf being nested under merge()...

If I try this expression https://github.com/OpenFn/lwala/blob/cda5f96c02603c565b85cda65cd23fed14bcb93f/commcare-salesforce-jobs/MOH513-Update-Household-in-SF-Production.js#L58-L108 but add in upsertIf (like below), and run it with this state.json https://gist.github.com/aleksa-krolls/feb14e374c047aec5c8cdb917eff991f --> it still upserts a Person record when it should not.

upsertIf(state => { var deaths = state.data.form.household_deaths.deaths_in_past_6_months; return (deaths > 0 ? true : false); }, "Person__c", "CommCare_ID__c", fields(

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/OpenFn/lwala/issues/17#issuecomment-618848422, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCUBLPOURGJ3V5V5E4S6PTROE4UNANCNFSM4MICSJTA .

-- Taylor Downs | Head of Product Open Function Group https://www.openfn.org/ | How Data Integration Makes ICT4D Work https://youtu.be/GVB9voGp6T4

taylordowns2000 commented 4 years ago

Yeah—looks like upsertIf doesn't take a function, it takes a logical... which is a frustrating difference.

On Fri, Apr 24, 2020 at 6:52 AM Taylor Downs taylor@openfn.org wrote:

Maybe a syntax thing? Replace line 68 upsert("Personc", "CommCare_ID__c", fields( with upsertIf((state.data.form.household_deaths.deaths_in_past_6_months > 0), " Personc", "CommCare_IDc", fields( and it should work. I've tested it with FakeAdaptor and the output is "Not upserting Personc because logical is false." Will wait for your confirmation before testing with Adaptor.

Taylor

On Fri, Apr 24, 2020 at 1:20 AM Aleksa Krolls notifications@github.com wrote:

@taylordowns2000 https://github.com/taylordowns2000 I'm still struggling to getting upsertIf() to work here and spending way too much time. Can we walk through tomorrow?

I'm finding the upsert always executes even if the logical is false. I'm wondering if it has something to do with this upsertIf being nested under merge()...

If I try this expression https://github.com/OpenFn/lwala/blob/cda5f96c02603c565b85cda65cd23fed14bcb93f/commcare-salesforce-jobs/MOH513-Update-Household-in-SF-Production.js#L58-L108 but add in upsertIf (like below), and run it with this state.json https://gist.github.com/aleksa-krolls/feb14e374c047aec5c8cdb917eff991f --> it still upserts a Person record when it should not.

upsertIf(state => { var deaths = state.data.form.household_deaths.deaths_in_past_6_months; return (deaths > 0 ? true : false); }, "Person__c", "CommCare_ID__c", fields(

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/OpenFn/lwala/issues/17#issuecomment-618848422, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCUBLPOURGJ3V5V5E4S6PTROE4UNANCNFSM4MICSJTA .

-- Taylor Downs | Head of Product Open Function Group https://www.openfn.org/ | How Data Integration Makes ICT4D Work https://youtu.be/GVB9voGp6T4

-- Taylor Downs | Head of Product Open Function Group https://www.openfn.org/ | How Data Integration Makes ICT4D Work https://youtu.be/GVB9voGp6T4

aleksa-krolls commented 4 years ago

Resolved with TD suggested change. Added to new job to run in parallel with this job to support 2 live CommCare form versions: https://github.com/OpenFn/lwala/commit/bd2f0414af56f0da1aa0380652c4604e55cb93fb