2
votes

in google app script i write following code to read response from google forms

function formResponse() 
{
    var form = FormApp.openById('form-id');
    var formResponses = form.getResponses();
    for (var i = 0; i < formResponses.length; i++)
    {
      var formResponse = formResponses[i];
      var itemResponses = formResponse.getItemResponses();
      for (var j = 0; j < itemResponses.length; j++) 
      {
        var itemResponse = itemResponses[j];
        Logger.log('Response #%s to the question "%s" was "%s"',
        (i + 1).toString(),
        itemResponse.getItem().getTitle(),
        itemResponse.getResponse());
      }
    }
  return formResponses;
 }

in google app script log has successful entry of what i expect.

in PHP i am using following code for call google app script.

$accessToken = $client->authenticate($request->input('code'));
$client->setAccessToken($accessToken);
$service = new \Google_Service_Script($client);
$scriptId = 'MIQpTICu_Gobs7BEB-v3lHZZMYprHmXMAQrb';
// Create an execution request object.
$request = new \Google_Service_Script_ExecutionRequest();
$request->setFunction('formResponse');
$responses = $service->scripts->run($scriptId, $request); 
$resp = $responses->getResponse();
print_r($resp);

it's not get any form responses values

1
There seems to have been a recent change. make sure you are opening the form with the /edit ID and not the /viewform IDSpencer Easton
@SpencerEaston i only give edit IDKalyana Kannan
Your code has a nested for loop, but then it returns formResponses. The for loops are not putting the data into a different object. Right now, the for loops are running, but they are effectively doing absolutely nothing to affect what gets returned by the function. Are you familiar with JSON.stringify(object)?Alan Wells
yes thank you. yesterday i found the answer..thank you for your timeKalyana Kannan

1 Answers

0
votes

i return formresponses instead of returning array object.