May 25, 202312:55 PM - last edited on May 26, 20238:51 AM by kvlschaefer
Contributor
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
Hi,
I wasn't actually sure where to put this. I am new to HubSpot. I am trying to use workflows to make a form submission create a ticket and associate that ticket with a deal. Advice on getting started would be greatly appreciated. I think it may take a custom code action, but what objects to use, etc, I don't really know.
This is an interesting idea, so a couple of questions for you:
1. What type of form is this? What does it do?
2. How do you want to associate the Deal? Does the form as for a deal ID?
The reason I ask these things is because if the form is a ticket form it will already create a ticket for you and bonus if you have a field on the ticket form that's the deal object record id property you can pretty easily create that in a new ticket workflow and just associate the deal with the ticket in a super simple custom code (which I can give you with a loom).
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
Thank you. I realized that the issue I was facing was that I couldn't do the put request through hubspotClient. I had to use Axios. It works now. I just wish I could pull the secret through hubspotClient without messing up Axios. That's still something for me to work on...
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
To echo CMcKay, there are a lot of moving pieces when it comes to giving advice for building out workflows that are going to be managing an association in your system.
The simplest version of this would be that you have either the Deal Id on the form as a mandatory field (unlikely, given that users shouldn't have their own Deal Id for any reason) or some kind of other unique identifier for the deal. In this case, you could make a workflow that triggers whenever a new ticket is created, and associate the ticket to the deal directly using the Deal Id, or by searching for the Deal using the API and then associating them.
Alas, that's almost never the case.
Assuming that your tickets are already being associated to contacts, more likely, you're going to want to create a ticket property that counts the number of associated contacts (calculated property). Then you create a ticket workflow that is triggered when the number of associated contacts is more than one.
Using the Associations API, grab all associated contacts. If there's a way to differentiate which is the most relevant contact, loop through them for that, otherwise I'd take the oldest one by default. Then use the Associations API to get all of that contact's associated deals, and filter through the deals with whatever criteria you're using to determine the most relevant deal. Finally, use the Associations API to associate the ticket with the deal.
This is a highly intensive process, requiring minimum 3 API calls per run, and potentially multiple Custom Code Actions to execute.
As @CMcKay said, if you can be more specific about exactly the process you want here (how are you determining which deal is the right one) we can likely give more detail! Also, if your tickets aren't being automatically associated to contacts, then you'd need to do another step in searching for the contact via the email address on the ticket.
This is an interesting idea, so a couple of questions for you:
1. What type of form is this? What does it do?
2. How do you want to associate the Deal? Does the form as for a deal ID?
The reason I ask these things is because if the form is a ticket form it will already create a ticket for you and bonus if you have a field on the ticket form that's the deal object record id property you can pretty easily create that in a new ticket workflow and just associate the deal with the ticket in a super simple custom code (which I can give you with a loom).
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
Not sure if this is just an artifact of the way you've shared the code, but it doesn't look like you're actually passing your id properties into the custom code action. You'd need to define them as inputs, and then use this code to make them available:
I believe that the issue I am having stems from the path I am dealing with... My error says:
ERROR TypeError: Cannot read properties of undefined (reading 'read')
at processEvent (/var/task/file.js:25:70)
at Object.exports.main (/var/task/file.js:7:19)
at Runtime.exports.hubspot_handler [as handler] (/var/task/hubspotHandler.js:6:21)
at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1086:29)
I think it is an issue here: "hubspotClient.crm.associations.batch.read.batchApi.createDefault" However, I am not sure how to fix this...
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
Can you try it again, but change "tickets" and "deals" back to "ticket" and "deal"? You had it like that originally, and I think that's correct. At very least you should get a different error.
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
Thank you. I realized that the issue I was facing was that I couldn't do the put request through hubspotClient. I had to use Axios. It works now. I just wish I could pull the secret through hubspotClient without messing up Axios. That's still something for me to work on...
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
@CMcKay Yes, that is exactly it. The dealID will be a hidden object in the form. Each form is sent with a custom link via email so that we ensure it will be the correct one. I am just working on the custom code action now. I would greatly appreciate the code in the loom you offered.
Custom Code - Make a form submission create a ticket and associate that ticket with a deal
SOLVE
This form creates a ticket for our customers. We will need a custom ticket property to add to it when the ticket is generated. Ultimately, though, the purpose is to associate the ticket with the deal that is tracking the user.
I want to invite our top experts to this conversation to share their thoughts @CMcKay@FNeri any recommendations to @ah8?
Thank you,
Pam
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!