+ Start a Discussion
澄人 鈴木 (Sumito)澄人 鈴木 (Sumito) 

Returned "Undefined" when using Google apps script to downloading Account data from Opportunity

Returned "Undefined" when using Google apps script to downloading Account data from Opportunity. Please help me to get proper record from Field "Account.Name".

Copied following method.
https://gist.github.com/stomita/990589

Modified as followings:

from: Opportunity
fields: Id,Account.Name

----
// Query account data from Salesforce, using REST API with OAuth2 access token.
  var fields = "Id,Account.Name";
  var soql = "SELECT "+fields+" FROM Opportunity LIMIT 100";
  var queryUrl = instanceUrl + "/services/data/v21.0/query?q="+encodeURIComponent(soql);
  var response = UrlFetchApp.fetch(queryUrl, { method : "GET", headers : { "Authorization" : "OAuth "+accessToken } });
  var queryResult = Utilities.jsonParse(response.getContentText());
----

ShinShin

You are referencing parent field (Account.Name) and the script just uses the root value of the record by its field path when rendering spread sheet.

```
  // Render result records into cells
  queryResult.records.forEach(function(record, i) {
    fields.forEach(function(field, j) { cell.offset(i+1, j).setValue(record[field]) });
  });
```

You should access nested property (Account.Name) properly in the JSON record.

澄人 鈴木 (Sumito)澄人 鈴木 (Sumito)
Thanks for your advice.

Since I am not engineer, need code-base help to complete this issue.
If you have any specific idea for above, please let me know.
Abdel BENDAOUAAbdel BENDAOUA
Sumito

Have you got any reply ?