Hello,

we need to synchronize some boolean values from Salesforce Cases to Drupal. My first idea was to enable synchronization of booleans in "salesforce_sync_api.inc" in function "_salesforce_sync_import_object_to_node" with these code lines:

'boolean'		=> array(
   'field_widget_type' => 'number_integer-number',
   'widget_type' => 'options_onoff',
   'description' => t('Boolean value required'),
   'module' => 'number, optionwidgets', 
   'default_value' => array ( 0 => array ( 'value' => 1, ), ),
),

.
In "salesforce_case.module" in function "salesforce_case_model_update" I will skip all not needed booleans. But I if create the new synchronization table and run the cron I will get some error message and synchronisation breaks.

How can I synchronize some booleans?

Thanks a lot,

Daniel

Comments

flymint’s picture

So, one example. I integratin the boolean like in post before. If I comment 'IsVisibleInCss' in the $skip-array out, and run "Synchronize your data model now" in Drupal, I getting the report with these additional lines

...
Created field Visible in Self-Service Portal.
Saved field Visible in Self-Service Portal.
...
1 fields inserted, 15 fields skipped

Then I changing two Cases in Salesforce, so that synchronization should done when the next cron runs. One has "Visible in Self-Service Portal" checked, one not.
If the cron runs next time, there are some warnings, (yesterday I get some errors)

Details
   Type     salesforce
   Date     Friday, January 18, 2008 - 1:13pm
   User     superadmin
   Location   http://xxx/admin/logs/status/run-cron
   Referrer   http://xxx/admin/logs/status
   Message   Subject,Id,CaseNumber,ContactId,SuppliedName,SuppliedPhone,SuppliedCompany,Type,Status,Origin,Priority,Description,ClosedDate,Bus_hrs_DE__c,IsCaseCreatedDuringBusinessHours__c,Customer_Ref__c,IsVisibleInCss
   Severity   warning
   Hostname   xxx.xxx.xxx.xxx

.
Furthermore both fields "field_case_isvisibleincss_value" in Drupal database table "drupal_content_type_salesforce_case" has a 0. In one there should be "1", shouldn't it?

bjacob’s picture

Assigned: flymint » Unassigned

EDIT: changed "Assigned"

... we can't find a solution. So it would be great if someone could give us a hint ...

eojthebrave’s picture

Should be fixed by this update. http://drupal.org/node/193235#comment-708565

eojthebrave’s picture

For clarification here's how I went about figuring this one out incase something like this comes up in the future.

The whole "sychronizing" the data model is really just taking the definition of a field returned by Salesforce and manipulating the values into something that can be used by drupal_execute to emuluate the steps that one would go through to create the field manually using CCK.

The first thing I usually do is just figure out, "If I was going to create the equivalent of this field in CCK how would I do it." Creating the field manually involves filling out two forms, one where you pick the widget type, and a second where you define the actual field itself. The Web Developer extension for Firefox has a tool that lets you "View form information" and shows you all the field names and their current/possible values for any form. I've been using that a bunch to figure out how I should be naming things for CCK, and what kind of values it expects.

I'm then basically using the _salesforce_sync_make_field function which has information passed to it about what kind of widget to use, and how Salesforce views this field. I then just try and manipulate the information from Salesforce into appropriate values for the CCK field. (I know what these are because I've already gone through the process of creating this field manually.)

In the _salesforce_sync_make_field function there are two large arrays $values, and $values2. Each one represents one of the "forms" used to when manually adding a field. Each index is the name of that form field and the value is the equivalent to what that form field would contain when you hit submit. The drupal_execute function then uses those two arrays to virtually submit the "forms" and create the content type.

Now you've got a field in CCK that functions in an equivalent manner to the one on Salesforce.

Then you just have to deal with getting data from and sending data to Salesforce.

The _salesforce_sync_get_object_data function is used to retreive information from Salesforce. So all I'm really doing here is figuring out the association between each Salesforce field and it's equivalent node field. (This information is stored earlier.) And then getting the value of the Salesforce field and manipulating it into an appropriate value for the $node field.

Booleans for example are represented in Salesforce as true/false values. However CCK doesn't have a widget that stores true/false values in the same manner so instead we create a single on/off checkbox using the Number widget with possible values of 0 or 1. Then in the _salesforce_sync_get_object_data I already know the Salesforce type, for each field and I can use a little switch logic to know if the field needs manipulation then perform the appropriate transformation.

In the case of booleans, I can use this code to map the true/false returned by Salesforce into 1/0 value for Drupal.

$form_values[$dp_field]['keys'] = ($obj->values[$sf_field] == "true") ? 1 : '';

Again, this whole function is basically setting everything up so that I can emulate submission of the node form via drupal_execute. Look at your node form and figure out what the value should be, and then in this function figure out how to transform the value returned by Salesforce into the value(s) expected.

Finally, when pushing information to Salesforce this function _salesforce_sync_put_object_data essentially does the exact opposite. It takes all the CCK fields for your node, and figures out how to transform them into a value that Salesforce can understand and deal with.

In the case of booleans it's reversing the transformation we made earlier from true = 1, false = 0

case 'boolean':
	settype($node->{$dp_field}[0]['value'], 'bool');
	$values[$sf_field] = $node->{$dp_field}[0]['value'];
	break;

So that Salesforce gets the true/false value it expects.

Hope this helps clear things up a little bit. Let me know if you have any questions. I look forward to seeing what you guys are doing with the module.

aaronbauman’s picture