简体   繁体   English

显示标签而不是内部值 (Google Apps Script/Google Sheets/HubSpot)

[英]Displaying Labels instead of Internal Values (Google Apps Script/Google Sheets/HubSpot)

You could say I'm a real newbie to coding.你可以说我是一个真正的编码新手。 Right now I'm trying to connect the HubSpot Account to Google Data Studio via Google Apps Script and Google Sheets.现在我正在尝试通过 Google Apps 脚本和 Google 表格将 HubSpot 帐户连接到 Google Data Studio。 I'm starting with simple stuff like in this example:我从这个例子中的简单内容开始:

https://medium.com/@alexisbedoret/create-a-hubspot-custom-dashboard-with-google-spreadsheet-and-data-studio-27f9c08ade8d https://medium.com/@alexisbedoret/create-a-hubspot-custom-dashboard-with-google-spreadsheet-and-data-studio-27f9c08ade8d

I tried to build my code like the one in the example above.我尝试像上面示例中的那样构建我的代码。 The problem is, that I'm getting the internal values of the "Deal Stage" and the "Pipeline" (the status if you will) the deals are in instead of the respective labels or names that are "attached" to the internal values (see photo)问题是,我正在获取交易所在的“交易阶段”和“管道”(如果您愿意的话,状态)的内部值,而不是“附加”到内部值的相应标签或名称(见照片)

谷歌表格的截图

Other stuff, like the Deal Name (or "Bewerbermanagementsystem" in the picture) is working properly.其他东西,如交易名称(或图片中的“Bewerbermanagementsystem”)工作正常。

Don't know if this is enough information for you guys, but it would be great if someone could help me, because I really do lack of knowledge in coding:D不知道这对你们来说是否足够,但如果有人能帮助我就太好了,因为我确实缺乏编码知识:D

Here's the section of the code:这是代码的一部分:

   function getDeals() {
   var service = getService();
   var headers = {headers: {'Authorization': 'Bearer '+ service.getAccessToken()}};
   var keep_going = true;
   var offset = 0;
   var deals = Array();
   while(keep_going) {
      var url = API_URL + "/deals/v1/deal/paged?properties=dealstage&properties=pipeline&properties=bewerbermanagementsystem&properties=amount&properties=dealname&properties=dealtype&limit=250&offset="+offset;
      var response = UrlFetchApp.fetch(url, headers);
      var result = JSON.parse(response.getContentText());
      keep_going = result.hasMore;
      offset = result.offset;
      result.deals.forEach(function(deal) {
         var dealstage = (deal.properties.hasOwnProperty("dealstage")) ? deal.properties.dealstage.value : 0;
         var pipeline = (deal.properties.hasOwnProperty("pipeline")) ? deal.properties.pipeline.value : 0;
         var bewerbermanagementsystem = (deal.properties.hasOwnProperty("bewerbermanagementsystem")) ? deal.properties.bewerbermanagementsystem.value : "unknown";
         var amount = (deal.properties.hasOwnProperty("amount")) ? deal.properties.amount.value : 0;
         var dealname = (deal.properties.hasOwnProperty("dealname")) ? deal.properties.dealname.value : 0;
         var dealtype = (deal.properties.hasOwnProperty("dealtype")) ? deal.properties.dealtype.value : 0;
         deals.push([stageId,pipeline,bewerbermanagementsystem,amount,dealname,dealtype]);
      });
   }
   return deals;
}

The need to write custom code to extract HubSpot data to a Google Sheets has largely been eliminated with the integration module provide by HubSpot. HubSpot 提供的集成模块很大程度上消除了编写自定义代码以将 HubSpot 数据提取到 Google 表格的需要。 The integration module works quite well to maintain a current list of objects (Contacts, Deals, etc.) and almost immediately mirrors in Sheets the data in HubSpot.集成模块可以很好地维护当前的对象列表(联系人、交易等),并且几乎可以立即在 Sheets 中反映 HubSpot 中的数据。

That said, the integration does only return the "internal values" of properties, and for Deal Stages for example, these may not be at all intuitive or relevant.也就是说,集成只返回属性的“内部值”,例如对于交易阶段,这些可能根本不直观或不相关。

I fixed this my creating a mapping table in Sheets that translates the raw data values imported from HubSpot into another column in the sheet with sensible values:我修复了这个问题,我在表格中创建了一个映射表,它将从 HubSpot 导入的原始数据值转换为表格中具有合理值的另一列:

名为 KeyValues 的工作表,其中包含默认 HubSpot 交易阶段的键值对映射表

Using an XLOOKUP array function in Google Sheets, you can translate an entire column of raw HubSpot values into meaningful relabelled ones.在 Google 表格中使用 XLOOKUP 数组 function,您可以将一整列原始 HubSpot 值转换为有意义的重新标记值。 The function is: function 是:

={"Stage";arrayformula(if($A$2:$A="", "", XLOOKUP($C$2:$C, KeyValues!$A$2:$A, KeyValues!$B$2:$B, na(), 0, 1)))}

This array function translates the entire Raw Stage column in one shot into the Stage column.这个数组 function 一次将整个原始舞台列转换为舞台列。 It should be placed in the header row of your data integration table.它应该放在数据集成表的header行中。 The array formula is better than using individual relative row-level formulas because it reduces the number of server round-trips required by Sheets and makes computation faster.数组公式优于使用单独的相对行级公式,因为它减少了 Sheets 所需的服务器往返次数并使计算速度更快。 You can then feed the translated column to pivot tables or other calcs.然后,您可以将翻译后的列提供给 pivot 表或其他计算。 I added the Index value associated with the mapped Label field to facilitate ordering categories in pivot tables.我添加了与映射的Label字段关联的索引值,以便于对 pivot 表中的类别进行排序。

显示原始值和映射值的工作表

The array function to lookup the Index value is nearly identical to the one used to look up the mapped data values:用于查找索引值的数组 function 与用于查找映射数据值的数组几乎相同:

={"Index";arrayformula(if($A$2:$A="", "", XLOOKUP($C$2:$C, KeyValues!$A$2:$A, KeyValues!$C$2:$C, na(), 0, 1)))}

I found that HubSpot will occasionally get confused and add duplicate rows, so I created the Dupe column that flags duplicate values based on a unique ID like Deal Name or the HubSpot recordID :我发现 HubSpot 偶尔会混淆并添加重复行,因此我创建了Dupe列,该列根据唯一 ID(如交易名称或 HubSpot recordID)标记重复值:

={"Dupe";arrayformula(if($A$2:$A="", "", COUNTIF($A$2:$A, $A$2:$A )-1))}

If you do see duplicates, it's important to know which row in the Google Sheet is actually the current record in HubSpot;如果您确实看到重复项,了解 Google 表格中的哪一行实际上是 HubSpot 中的当前记录非常重要; you should always export the recordID in your data and you can then construct a URL to see what the Sheets row refers to using a formula like this:您应该始终导出数据中的recordID ,然后您可以构造一个 URL 以使用如下公式查看 Sheets 行引用的内容:

={"URL";arrayformula(if($A$2:$A="", "", "https://app.hubspot.com/contacts/[Your HubSpot ID goes Here]/deal/"&$F2:F))}

The unnecessary (duplicate) row in your sheet will result in a 404 error in HubSpot, so that's the one you can delete.工作表中不必要的(重复的)行将导致 HubSpot 出现 404 错误,因此您可以删除该行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM