EasyUI Forum
November 05, 2025, 05:06:11 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Passing Sales Force Data into a Data Grid  (Read 13152 times)
peter900
Newbie
*
Posts: 22


View Profile Email
« on: August 23, 2016, 02:59:18 PM »

I am trying to load Sales Force data into a Data Grid using the CRUD example.

I have generated JSON from a Sales Force Query.  Here is an extract:

{
   "queryLocator":null,
   "done":true,
   "records":[
      {
         "Id":null,
         "CreatedDate":"2016-08-17T20:43:10.000Z",
         "Leader__c":"GF",
         "Lectionary6__r":{
            "Id":null,
            "Colour__c":"Green",
            "Lectionary_Date__c":"2016-09-04",
            "Period_Name__c":"Trinity 15",
            "Selected_Reading_Line__c":"Deuteronomy 30.15\u2013end, Psalm 1, Philemon 1\u201321, Luke 14.25\u201333"
         },
         "Location__c":"Ashburton",
         "Service_Date__c":"2016-09-04",
         "Service_Time__c":"08:00",
         "Service_Type__c":"HC 2"
      },
      {
         "Id":null,
         "CreatedDate":"2016-08-17T20:43:10.000Z",
         "Leader__c":"GF",
         "Lectionary6__r":{


Here is the JSON which comes from the CRUD example



{
   "total":"105",
   "rows":[
      {
         "id":"3",
         "firstname":"fname1234BBBB",
         "lastname":"lname10....",
         "phone":"Lacock 4919999",
         "email":"name991@gmail.com"
      },
      {
         "id":"7",
         "firstname":"fname413ffffggxx",
         "lastname":"lname999x",
         "phone":"0123456",
         "email":"name4@gmail.com"
      },

Here are the important lines from get_users.php which create the JSON array.

Code:
define("USERNAME", "--------------------");
define("PASSWORD", "--------");
define("SECURITY_TOKEN", "-----------");

require_once ('soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/generateEnterprise.wsdl");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$query = "SELECT Service_Date__c, Service_Time__c, CreatedDate, Notes__c, Leader__c, Location__c, Service_Type__c,  Lectionary6__r.Lectionary_Date__c,Lectionary6__r.Colour__c,Lectionary6__r.Period_Name__c, Lectionary6__r.Selected_Reading_Line__c from Service3__c WHERE Web_Publish__c = True ORDER BY Service3__c.Service_Date__c, Service3__c.Service_Time__c
";

$response = $mySforceConnection->query($query);

$data = json_encode((array)$response);

echo $data;


The SF JSON validates - the only difference I can see relates to the header - the EasyUI includes the number of rows.  Is this important ?  Can anyone suggest what I need to change to get the SF data to load into the grid ?  Any help or suggestions much appreciated. Thanks.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #1 on: August 23, 2016, 06:52:54 PM »

Please look at this topic http://www.jeasyui.com/forum/index.php?topic=1727.0
Logged
peter900
Newbie
*
Posts: 22


View Profile Email
« Reply #2 on: August 24, 2016, 03:46:28 AM »

Thanks for this url. 

I have added this JavaScript at the head of the page displaying the list:

Code:
<script type="text/javascript">
var url;

$('#dg').datagrid({
loadFilter: function(data){
total: data.total, ,
rows: data.records
}
})

However I get two errors:

Syntax Error: total: data.total   "Expecting expression, got ','
Type Error: Rows is undefined

Here is a sample of the response data:

Code:
{
   "queryLocator":null,
   "done":true,
   "records":[
      {
         "Id":null,
         "CreatedDate":"2016-08-17T20:43:10.000Z",
         "Leader__c":"GF",
         "Lectionary6__r":{
            "Id":null,
            "Colour__c":"Green",
            "Lectionary_Date__c":"2016-09-04",
            "Period_Name__c":"Trinity 15",
            "Selected_Reading_Line__c":"Deuteronomy 30.15\u2013end, Psalm 1, Philemon 1\u201321, Luke
 14.25\u201333"
         },
         "Location__c":"Ashburton",
         "Service_Date__c":"2016-09-04",
         "Service_Time__c":"08:00",
         "Service_Type__c":"HC 2"
      },
      {
         "Id":null,
         "CreatedDate":"2016-08-17T20:43:10.000Z",
         "Leader__c":"GF",
         "Lectionary6__r":{
            "Id":null,
            "Colour__c":"Green",
            "Lectionary_Date__c":"2016-09-04",
            "Period_Name__c":"Trinity 15",
            "Selected_Reading_Line__c":"Deuteronomy 30.15\u2013end, Psalm 1, Philemon 1\u201321, Luke 14.25\u201333"
         },
         "Location__c":"Bickington",

Your solution seems close as the data format is exactly as per the post you referred to. Is the problem the absence of a Total element in the JSON ?

Any further thoughts please ?   Thanks.
Logged
peter900
Newbie
*
Posts: 22


View Profile Email
« Reply #3 on: September 08, 2016, 03:25:26 PM »

Here is the code that achieves what I wanted - taking output from a Sales Force query and formatting it as required by a EasyUI datagrid.

Code:

 //--Get the Sales Force Data
 $response = $mySforceConnection->query($query);

//--Encode and decode - for some reason
$data = json_encode((array)$response);
$x = json_decode($data,true);

//--Empty Array
$q = array();


//--Add array element for number records
$q['total'] = $numRecs;
//--Copy the array element from original query with data
$q['rows'] = $x['records'];

//--JSON Encode the new array
$y = json_encode($q);

//--Return the array to Ajax call
echo ($y);



And here's a snippet of the validated JSON..


Code:

 "total":193,
 "rows":[ 
  { 
     "Id":null,
     "CreatedDate":"2016-08-28T14:43:45.000Z",
     "Leader__c":"GF",
     "Location__c":"Postbridge",
     "Service_Date__c":"2016-09-03",
     "Service_Time__c":"14:30",
     "Service_Type__c":"Baptism"
  },
  { 
     "Id":null,
     "CreatedDate":"2016-08-17T20:43:10.000Z",
     "Leader__c":"GF",
     "Location__c":"Ashburton",
     "Service_Date__c":"2016-09-04",
     "Service_Time__c":"08:00",
     "Service_Type__c":"HC 2"
  },
  { 
     "Id":null,
     "CreatedDate":"2016-08-17T20:43:10.000Z",
     "Leader__c":"GF",
     "Location__c":"Bickington",
     "Service_Date__c":"2016-09-04",
     "Service_Time__c":"09:00",
     "Service_Type__c":"HC 2"
  },
  { 
     "Id":null,
     "CreatedDate":"2016-08-17T20:43:10.000Z",
     "Leader__c":"MC",
     "Location__c":"Holne",
     "Service_Date__c":"2016-09-04",
     "Service_Time__c":"10:30",
     "Service_Type__c":"HC 1"
  },

</code>
I struggled a bit with the array manipulation but it works. Any code improvement suggestions most welcome !
Logged
battlezad
Newbie
*
Posts: 44


View Profile
« Reply #4 on: September 09, 2016, 04:48:07 AM »

You have extra comma in the following line:

total: data.total,         ,

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!