APIs & Integrations

RReiffer
投稿者

Issue with my code not writing data back to a Deal with the updated value

解決

All,

I am trying to do the following in Deals.  If the amount is null or = 0 then replace the amount with the Total Contract Value (hs_tcv).  My flow appears to do everything, no errors but the amount field stays blank.  Below is the code and a screen shot of my input and output variables.

const hubspot = require('@hubspot/api-client');
 
exports.main = async (event, callback) => {
 
    const hubspotClient = new hubspot.Client({
        accessToken: "pat-na1-NOPE"
    });
    //console.log("Made it past OAuth")
    //First, make a call to get deal associations  
    var amount = event.inputFields['amount'];
        //console.log(amount)
        var hs_mrr = Number(event.inputFields['hs_mrr']);
  var hs_tcv = event.inputFields['hs_tcv'];
  //const closedate = event.inputFields['closedate'];
//console.log(hs_tcv)
      //console.log("1",amount)
      var amount_new = amount
        if(amount_new > 0) {var amount_new = amount} else {var amount_new = hs_tcv}
        //console.log("2",amount_new)
    amount = amount_new
        //console.log("3", amount)
        callback({
        outputFields: {
          amount: amount
        }
      });
}

RReiffer_0-1687281986121.png

 

0 いいね!
1件の承認済みベストアンサー
RReiffer
解決策
投稿者

Issue with my code not writing data back to a Deal with the updated value

解決

Hey everyone, I finally figured it out (duh).  I needed to add a step in the workflow that actually copies that value BACK to the deal from the custom code.   I assumed that the code actually wrote data back but it only writes data back to the custom code workflow object. 

RReiffer_0-1687284455592.png

 

元の投稿で解決策を見る

8件の返信
HubDoPete
ガイド役 | Gold Partner
ガイド役 | Gold Partner

Issue with my code not writing data back to a Deal with the updated value

解決

Hi Richard, I'm curious why you wrote custom code for this.

 

If your Deal workflow:

  • triggers on MRR property is 'known', and permits deal re-enrollment
  • then copies the Deal MRR property to Deal Amount
  • will that also suffice?

best

Pete

0 いいね!
RReiffer
投稿者

Issue with my code not writing data back to a Deal with the updated value

解決

Pete,

Wew wanted to have Total Contract Value and not MRR.

Rich

0 いいね!
HubDoPete
ガイド役 | Gold Partner
ガイド役 | Gold Partner

Issue with my code not writing data back to a Deal with the updated value

解決

Hi Richard, in that case, could you just copy across the Deal TCV?

  • workflow triggers on TCV property is 'known', and permits deal re-enrollment
  • then copies the Deal TCV property to Deal Amount

That property is also automatically updated by HubSpot per deal. If you need custom code then sure thing - I was just curious as there are four calculated fields on each deal that you can copy to deal amount:

  • Total contract value (TCV),
  • Annual contract value (ACV),
  • Annual recurring revenue (ARR)
  • and Monthly recurring revenue (MRR).

We ended up writing a help page on automating deal value because it comes up regularly for apps like DoPricer which change line item prices and discounts in the background via the API. So the workflow keeps the deal amount accurate.

 

best

Pete

 

0 いいね!
KimM
トップ投稿者

Issue with my code not writing data back to a Deal with the updated value

解決

Hey @RReiffer , Glad to see you found a solution to this.

 

I did notice that in your initial post you've used what looks like your access token. Just wanted to make sure that you changed this as otherwise people can access your Hubspot data via API with this.

 

Happy Hubspotting!

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

Issue with my code not writing data back to a Deal with the updated value

解決

Good catch, @KimM 🙌 I went ahead and edited it out of the original post. And, @RReiffer should definitely rotate that key if they haven't already. — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 いいね!
RReiffer
投稿者

Issue with my code not writing data back to a Deal with the updated value

解決

Done! Thanks

0 いいね!
RReiffer
投稿者

Issue with my code not writing data back to a Deal with the updated value

解決

Hi @Teun@louischausse@johnelmer - here is the code I was referring to.  Thanks

0 いいね!
RReiffer
解決策
投稿者

Issue with my code not writing data back to a Deal with the updated value

解決

Hey everyone, I finally figured it out (duh).  I needed to add a step in the workflow that actually copies that value BACK to the deal from the custom code.   I assumed that the code actually wrote data back but it only writes data back to the custom code workflow object. 

RReiffer_0-1687284455592.png