RevOps & オペレーション

natsumimori
コミュニティーマネージャー
コミュニティーマネージャー

📹カスタムコード活用方法<取引レコードを毎月生成する>

Operations Hubの新機能であるカスタムコードを使用して、取引レコードを毎月生成する方法をご紹介します。サブスクリプションビジネスをされている方には特に役立つ情報だと思いますので、ぜひこちらのビデオでチェックしてみてください。(カスタムコードとは?)

 

 

<毎月取引レコードを生成するカスタムコード>

*あくまでサンプルコードですので、動作に関してHubSpotは責任を負いません。あらかじめご了承ください。

GitHubリンクはこちら

都道府県名を書式統一するカスタムコード例はこちら

 

const hubspot = require('@hubspot/api-client')

/**
* HubSpot will display an error when you paste this code, but it actually
* works if you ignore it and just save it.
* Workflow action to create a new deal on the same close date every month
* The date has to be 1st - 28th.
* If the date is 29th - 31st, the dates will be off at some point.
*
* Also, watch your API limit. This custom action calls the API 3 times everytime it runs.
*/
exports.main = async(event, callback) = > {

const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});

const dealId = event.object.objectId

const results = await hubspotClient.crm.deals.basicApi.getById(dealId, ['closedate', 'amount', 'dealname', 'dealstage', ])

const deal = results.body.properties

const closeDate = new Date(deal.closedate)

closeDate.setMonth(closeDate.getMonth() + 1)
closeDate.setMilliseconds(0)
closeDate.setSeconds(0)
closeDate.setMinutes(0)
closeDate.setHours(0)

const newDealData = {
properties: {
closedate: closeDate.getTime(),
amount: deal.amount,
dealname: deal.dealname,
dealstage: deal.dealstage,
}
}

const res = await hubspotClient.crm.deals.basicApi.create(newDealData)

// Associate the new deal with the company that was originally associated with
const newDealId = res.body.id
const associations = await hubspotClient.crm.deals.associationsApi.getAll(dealId, 'companies')
if (associations.body.results.length > 0) {
await hubspotClient.crm.deals.associationsApi.create(newDealId, 'companies', associations.body.results[0].id, 'deal_to_company')
}

callback({
outputFields: {}
})
}

 

 


Join us on March 27th at 12 PM for the Digital Essentials Lab, an interactive session designed to redefine your digital strategy!
Engage with expert Jourdan Guyton to gain actionable insights, participate in live Q&A, and learn strategies to boost your business success.
Don't miss this opportunity to connect and grow—reserve your spot today!

0件の返信

0 コメント

この投稿にはまだ回答がありません

この投稿にはまだ回答が寄せられていません。しばらく経ってからもう一度ご確認ください。また、役に立つ情報をご存じの場合はぜひ回答を投稿してください。

投稿に回答する

回答の仕方についてご不明な場合は、コミュニティーのガイドラインをご覧ください。