Announcement

Collapse
No announcement yet.

Why does app work in Blank App and NOT in Grid On Record

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why does app work in Blank App and NOT in Grid On Record

    Hi, I am very confused, please can someone direct me here.

    I have a blank app with the below code. It works perfectly when I run it as a blank app.
    I then copied it exactly to the "onRecord" in a Grid application, and when I run the Grid application it works perfectly.

    Here is the confusion:.
    I change the 'from' and 'to' values instead of being hard coded to a values as per table field values in the grid ( {startLocation} and {toLocation} respectfully). I get a series of errors.
    Error
    Undefined property: stdClass::$duration
    Error
    Trying to get property of non-object
    Error
    Undefined property: stdClass::$distance
    Error
    Trying to get property of non-object
    The exact code is:

    $from = "22 Centre Rd, Morningside Sandton Gauteng South Africa"; // {startLocation}
    $to = "123 Main Street, Johannesburg Gauteng South Africa"; // {toLocation}
    $from = urlencode($from);
    $to = urlencode($to);
    $data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");
    $data = json_decode($data);
    $seconds = 0;
    $distance = 0;
    foreach($data->rows[0]->elements as $road) {
    $seconds += $road->duration->value;
    $distance += $road->distance->value;
    }
    $hours = floor($seconds / (60 * 60));

    // extract minutes
    $divisor_for_minutes = $seconds % (60 * 60);
    $minutes = floor($divisor_for_minutes / 60);

    // extract the remaining seconds
    $divisor_for_seconds = $divisor_for_minutes % 60;
    $seconds = ceil($divisor_for_seconds);

    //create string HH:MM:SS
    $ret = $hours.":".$minutes.":".$seconds;
    {kms}=$distance*0.001; /// shows distance in km's between {startLocation} and {toLocation}
    Last edited by Larryh1115; 05-19-2016, 06:19 AM.

  • #2
    Probably some missing information (duration/distance) in $data.
    You can check $data value with the code below:

    ps: it helps if you post a print screen with the result of this code, so we can better understand what is happening

    Code:
    // put these lines right after the $data = json_decode($data);
    echo "<pre>";
    var_dump($data);
    die();
    SC Tools: A browser extension to make working with ScriptCase simpler and even more productive.

    http://blog.andersonmamede.com.br

    Comment

    Working...
    X