繁体   English   中英

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

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

你可以说我是一个真正的编码新手。 现在我正在尝试通过 Google Apps 脚本和 Google 表格将 HubSpot 帐户连接到 Google Data Studio。 我从这个例子中的简单内容开始:

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

我尝试像上面示例中的那样构建我的代码。 问题是,我正在获取交易所在的“交易阶段”和“管道”(如果您愿意的话,状态)的内部值,而不是“附加”到内部值的相应标签或名称(见照片)

谷歌表格的截图

其他东西,如交易名称(或图片中的“Bewerbermanagementsystem”)工作正常。

不知道这对你们来说是否足够,但如果有人能帮助我就太好了,因为我确实缺乏编码知识:D

这是代码的一部分:

   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;
}

HubSpot 提供的集成模块很大程度上消除了编写自定义代码以将 HubSpot 数据提取到 Google 表格的需要。 集成模块可以很好地维护当前的对象列表(联系人、交易等),并且几乎可以立即在 Sheets 中反映 HubSpot 中的数据。

也就是说,集成只返回属性的“内部值”,例如对于交易阶段,这些可能根本不直观或不相关。

我修复了这个问题,我在表格中创建了一个映射表,它将从 HubSpot 导入的原始数据值转换为表格中具有合理值的另一列:

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

在 Google 表格中使用 XLOOKUP 数组 function,您可以将一整列原始 HubSpot 值转换为有意义的重新标记值。 function 是:

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

这个数组 function 一次将整个原始舞台列转换为舞台列。 它应该放在数据集成表的header行中。 数组公式优于使用单独的相对行级公式,因为它减少了 Sheets 所需的服务器往返次数并使计算速度更快。 然后,您可以将翻译后的列提供给 pivot 表或其他计算。 我添加了与映射的Label字段关联的索引值,以便于对 pivot 表中的类别进行排序。

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

用于查找索引值的数组 function 与用于查找映射数据值的数组几乎相同:

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

我发现 HubSpot 偶尔会混淆并添加重复行,因此我创建了Dupe列,该列根据唯一 ID(如交易名称或 HubSpot recordID)标记重复值:

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

如果您确实看到重复项,了解 Google 表格中的哪一行实际上是 HubSpot 中的当前记录非常重要; 您应该始终导出数据中的recordID ,然后您可以构造一个 URL 以使用如下公式查看 Sheets 行引用的内容:

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

工作表中不必要的(重复的)行将导致 HubSpot 出现 404 错误,因此您可以删除该行。

暂无
暂无

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

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