Buy Now
Sign in

Selecting data from a 3rd Party DB

tshirley , August 07 at 10:09
t
tshirley

Hello,

My application uses Salesforce as it's primary DB and in CF5 and CF6 I can use a REST API to draw data into the forms for processing using custom php and CURL.

I am now trying to achieve the same results with CC6, and I am sure it is possible but I can't get it to work.

Basically I want to execute some php (which I already have working in CC5 and 6) to return an associative array containing the data I want to display. The code returns an array in the form:

				
myarray

[0]
[Field1] => data1
[Field2] => data2
...
[1]
[0]
[Field1] => data3
[Field2] => data4
...



So I placed this code in a custom code object and ticked the "return in a var" option. But it didn't give any result, and I didn't know exactly how to use the {debug:} to see what is going on.

Any assistance would be much appreciated.

Tim

t
tshirley

Sorry, the example code should be:

				

myarray

[0]
[Field1] => data1
[Field2] => data2
...
[1]
[Field1] => data3
[Field2] => data4
...



basically, a valid associative array.

Tim

admin

Hi Tim,

Please use a "Logic > PHP" function instead, and "return" the results, then it should be available under {var:php_fn_name}

Best regards,
Max

Max
If your main question got answered then please mark the answer using the button!

t
tshirley

Thanks Max,

I created a Logic/PHP function named "clubinfo" and put in the following code that works correctly in CF5 and 6 :

				

// include API functions

include JPATH_SITE.'/components/com_chronoforms5/chronoforms/includes/sfAPI.php';

// authorise to 3rd party DB

$auth = authSF();
$sfaccess = $auth[0];
$latestversion = $auth[1]['version'];

$q = "SELECT+LastName,Email,Website__c,Facebook_Page__c,Nearest_Town_to_Site__c+from+Contact+WHERE+Membership_Type_L__c='Club'+AND+Status_L__c='Active'";

$clubdata = querySF($sfaccess,$latestversion,$q);

// comment out the CF5 code
// $form->data['clubdata'] = $clubdata;

return $clubdata;



I then used {fn:clubinfo} in my index event, and {var:php_clubinfo} as the DAta provider in a table view. Running the list indicates that the API call is working, there is evidence from the browser that it does communicate with the server.

However,

The result was that no data is displayed, although and a {debug:} shows only:

				
Array
(
[option] => com_chronoconnectivity6
[cont] => manager
[conn] => clublistfromlocator-copy
[__utma] => 56146813.1332169317.1437286808.1457526671.1457653256.141
[69acbdca18c366bd0fda2fd3c2f798f1] => vc933ge3o2mru4cdfrdis2shc6
[jpanesliders_contact-slider] => 0
[c0b3da5e2c719fc1d8c4287f74bf65ff] => ben17232ogit56nhjqai3bfug7
[_ga] => GA1.2.1332169317.1437286808
)




So there is no indication in the debug that any var is created.

I then tried commenting out my API code and executing only a single line "return 'test';" to see if it was my API calls that were the problem, but got the same result.

I'm obviously very close to getting this working. Hope you can see what I am doing wrong.

Tim

admin

Hi Tim,

If the function name is "clubinfo" then you have to use {var:clubinfo}

Best regards,
Max

Max
If your main question got answered then please mark the answer using the button!

t
tshirley

Hi Max,

Thanks again.

Still not much progress. I changed the data provider to {var:clubinfo} in the table view, and then used clubinfo as the Model Name, so like: clubinfo.field1:Title1

This produced 3 blank rows under the title line and then the debug info as above. I had thought that the var:clubinfo result would be reported in the debug, in a similar way that i am used to seeing in a chronoform debugger action.

It does appear that the API code is working, and I am still having trouble with the syntax of var and model names etc.

Sorry, this is obviously something very simple that I am missing.

Tim

t
tshirley

Hi,

As a further test I took out my more complex code and created a basic array in the function like this:

				
$clubdata = array ([0] => array (
'LastName' => "GCV",
'Nearest_Town_to_Site__c' => "Benalla"),
[1] => array (
'LastName' => "Horsham",
'Nearest_Town_to_Site__c' => "Horsham"));

return $clubdata;


I have checked this code and it is valid php.

the function is called clubinfo, so i was expecting that after the function is executed there will be a {var:clubinfo} with the array in it, and that this will appear in the "Array" section of the {debug:}

However, nothing appears there.

So now I am suspecting that the function is not being called, or for some reason it is not returning a result. I have placed the function {fn:clubinfo} as the first item in the index event.

Does this help with the diagnosis?

Tim

admin

Hi Tim,

Unfortunately the php function did not have a debug result, I have added this and it should be available in the next update.

But if your function is returning something then it should be available under {var:clubinfo}

Best regards,
Max

Max
If your main question got answered then please mark the answer using the button!