Google电子表格 - 从Zoho获取记录

时间:2016-02-26 19:41:57

标签: javascript google-apps-script zoho

来自谷歌传播,我正试图从Zoho收集记录。

我测试了这段代码:

var urlgetRecords = 'https://crm.zoho.com/crm/private/json/Leads/getRecords?newFormat=1&authtoken=00000&scope=crmapi&selectColumns=Leads(First Name,Last Name,Email)&fromIndex=1&toIndex=2&sortColumnString=First Name&sortOrderString=desc';

var jsonResponse = UrlFetchApp.fetch(urlgetgetRecords);

这是获得:

  

{ “响应”:{ “结果”:{ “信息”:{ “行”:[{ “无”: “1”, “FL”:[{ “内容”: “1412559000000441145”, “VAL” : “LEADID”},{ “内容”: “维克托”, “VAL”:“首先   姓名“},{”content“:”Aguilera Moreno“,”val“:”最后   名 “},{” 内容 “:” v-aguilera@hotmail.com “ ”VAL“: ”电子邮件“}]},{ ”无“: ”2“, ”FL“:[{ ”内容“:” 1412559000000308001" , “VAL”: “LEADID”},{ “内容”: “维克多”, “VAL”:“第一   名称 “},{” 内容 “:” 门 “ ”VAL“:” 最后   名称 “},{” 内容 “:” vporta@test.es”, “VAL”: “电子邮件”}]}]}}, “URI”: “/ CRM /私营/ JSON /信息/ getRecords”}} < / p>

请问,如何在电子表格中写下此回复中的每一行?

非常感谢您提前:))

2 个答案:

答案 0 :(得分:1)

Sandy Good的代码非常完美。 我不得不再添加两行。

最后有效的代码是:

&#13;
&#13;
var urlgetRecords = 'https://crm.zoho.com/crm/private/json/Leads/getRecords?newFormat=1&authtoken=' + authToken + '&scope=crmapi&selectColumns=Leads(First Name,Last Name,Email)&fromIndex=1&toIndex=2&sortColumnString=First Name&sortOrderString=desc';
var jsonResponse = UrlFetchApp.fetch(urlgetRecords);
 var jsonText = jsonResponse.getContentText();
 var objetoFinal = JSON.parse(jsonText);
 writeZohoToSheet(objetoFinal);
&#13;
&#13;
&#13;

非常感谢你的帮助@SandyGood

答案 1 :(得分:0)

将ZOHO数据写入Google电子表格。要使用下面的代码,请将getSheetByName('Sheet2')方法中的工作表标签名称编辑到要将数据附加到的工作表标签中。

我已经测试了这段代码,但它确实有效:

function writeZohoToSheet(zohoDataObject) {
  var zohoDataObject = {"response":
                        {"result":
                         {"Leads":
                          {"row":
                           [{"no":"1","FL":[
                              {"content":"12345678IDNumber","val":"LEADID"},
                              {"content":"Víctor","val":"First Name"},
                              {"content":"Aguilera Moreno","val":"Last Name"},
                              {"content":"v-agEmailTest@hotmail.com","val":"Email"}]
                            },
                            {"no":"2","FL":[
                              {"content":"987654321IDNumber","val":"LEADID"},
                              {"content":"Victor","val":"First Name"},
                              {"content":"Porta","val":"Last Name"},
                              {"content":"someEmail@test.es","val":"Email"}]
                            }
                           ]
                          }
                         },"uri":"/crm/private/json/Leads/getRecords"}};

  var rows = zohoDataObject.response.result.Leads.row;
  Logger.log('rows: ' + rows);
  Logger.log('rows.length: ' + rows.length);

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName('Sheet2');
  var array = [], thisRow, thisContent, innerObj;

  for (var r in rows) {
    array = []; //reset
    thisRow = rows[r];
    thisContent = thisRow.FL;

    array.push(r);

    for (var i=0;i<thisContent.length;i+=1) {
      innerObj = thisContent[i];
      array.push(innerObj.val);
      array.push(innerObj.content);
    };

    sh.appendRow(array);
  }; 
};

您可以使用以下方法调用该函数:

writeZohoToSheet(jsonResponse);

删除“硬编码”对象文字,或将其注释掉以传入检索到的对象。