Update using Salesforce adaptor- handling blank values


Glad to inaugurate this group. I am writing a job sending CommCare forms into Salesforce. I am wondering if there is any way to set a field() pairing that only fires when the data value is not null.

In my use case, for example, I have a bunch of fields associated with data values from a CommCare form. Sometimes, a few values from the form will be missing (meaning the CommCare user skipped a question). When this happens during an update, the data values in the job are set to null for the missing fields, and the corresponding Salesforce fields are set to null. Is there any way to signal so that when a data value is null, the Salesforce field is unchanged instead of set to null? Am I making sense?

Hey Will, it definitely makes sense* but we’ve never come across it in the past… Is it possible that this is an issue better handled with your system design?

If I’m understanding correctly, you’re updating existing records in Salesforce by submitting new records in CommCare. That’s lossy. I’d much rather either set up CommCare so that you’re doing updates (so what you’re passing to Salesforce is the case and not the form) or set up a custom object in Salesforce to help reflect what’s taking place in CommCare. Create an object that is child to whatever you’re currently upserting to, and upsert to that, using the CommCare submission UUID as your unique value. Then, you’ll have an accurate representation of what data your enumerators are actually creating and you can (1) update the parent (“case”) in Salesforce in whatever way you’d like and (2) sort out your enumerators for skipping questions!

If you’re willing, I’d love to take a look at the design of your forms and cases on CommCare. I can’t quite visualize the situation in which this partial update is taking place and is valid—i.e., they really should be skipping questions.

*I think what you want is the ability to do this in an expression:
... field("foo", "bar"), function(state) { if (dataValue("qux")(state) !== null) { return field("baz", dataValue("qux")(state)) } else { return null } }, ...

Do I have that right?


Thanks, Taylor.

You are right. My CommCare setup consists of Household cases and Person child cases, and I have corresponding Household and Person objects in Salesforce. My goal was to use one Job to accommodate registration and update forms on the household object, i.e., if I filled out the registration form, Salesforce would insert a new record, and if I filled out the update form, Salesforce would update the record. However, I think you are right that having a “survey” object or something similar in Salesforce to accommodate the update forms would work much better, especially for monitoring individual entries.

Along similar lines as previous question, I am wondering if it is possible to execute actions in a job on a conditional basis. Something that would look like this:


> create('Event__c',fields(.....));


In this case, I have a question in an update form asking if a mother gave birth. If the answer is “Yes”, I want to create an Event record in Salesforce with information about the circumstances of the delivery. However, if the answer is “No”, I wouldn’t want to create a record. Is this possible?

Will, sorry for the delay here. Try using “combine(…)”. The documentation for it is here (https://github.com/OpenFn/language-common/blob/master/src/index.js#L217-L235) and I’ve pasted some sample code that works for me below:

combine( function(state) { if (state.data.something_true) { return create("Beneficiary__c", fields( field("name", dataValue("patient_name")), field("Country__c", "Kenya"), relationship("House__r", "house_id__c", "007"), relationship("RecordType", "name", "mobile_clinic_patient") ))(state); } })

Hi Taylor,

Great, this is exactly what I was looking for. Thanks!

Wonderful. Note that not all language packages import “combine”. You’ll be fine with language-salesforce but if folks need to do this with other language-packages they may need to submit a PR after adding “combine” to the list of imports in /src

El El mar, ene. 3, 2017 a las 9:41 AM, <will@lwalacommunityalliance.org> escribió: