I’m working to develop a custom-coded JavaScript workflow action for deals and I’ve got most of what I need, but I’m stuck on one part.
The requirement that’s been given to me is that it needs to have a prefix based on date (that part is done), and an index. As an example, if it’s September 2023, the first deal would have a code of 230901 (year/month/index). Second is 230902, third is 230903, etc. Then for October the index would restart so the code would start at 231001.
The date part is fine, but I cannot find a way to get an index value that I can increment for each deal and be able to use globally.
What I’ve tried so far is to set variables outside of the exports.main function that from what I’ve read are meant to work as global values, but these aren’t saving or storing between the times the workflow is called.
Is there any way that anyone knows of to be able to set and retrieve the value for an index that can be used like this?
Hi, @MichaelBeaumont
Thanks for your question. I’d like to invite some community members to the conversation — hey @JBeatty @ChrisoKlepke @Mike_Eastwood, do you have any experience with this kind of project? Or have you approached similar challenges differently recently?
Thank you! — Jaycee
Asa bit more information, I have tried to use ‘Secrets’ for this, but in testing these reset after I leave the session that I’m in. I set them yesterday, but today they have reset back to being empty again.
As that’s only in the testing area, and not in a Workflow that’s been published, is that behaviour expected, or is that how secrets work, and they don’t hold the value universally?
I’m still hoping that someone out here has an idea of what can be done.
If not, this sounds like something that HubSpot might think about adding in?
Hi @MichaelBeaumont
If you have access to Ops Hub you could write a function to search for and Deals, by date, then use Count + 1 to create your Deal code.
e.g. get all Deals by date, count the deals, add one, and append it to your Deal Code.
Have fun
Mike
p.s. thank you for the mention @Jaycee_Lewis
Here to learn more about HubSpot and share my HubSpot Knowledge. I’m the founder of Webalite a HubSpot Partner Agency based in Wellington, New Zealand and the founder of Portal-iQ the world’s first automated HubSpot Portal Audit that helps you work smarter with HubSpot.
@Mike_EastwoodThat sounds like it would work. Apart from one other criteria that I left out for the sake of simplicity.
There also needs to be a three-letter prefix on each ID that will change depending on some other arbitrary options. At the moment there’s three possible prefix’s but there could be any number more in the future. As an example you’d have deals with an ID of PRE230901, PRE230902, JUS230901, INT230901. Each prefix has to have it’s own index number that doesn’t relate to the number of deals, just the number of deals for that prefix for that month, so just countng only deals for the month won’t handle that.
That’s why I was searching for a global value. That way I know that if I can set one, I can set multiple and cater for every iteration of prefix that is thought up in the future.
Right now we’re trying to talk the client out of this as it seems like there’s no way to get this to work.
Hi @MichaelBeaumont
Depending on where the prefix comes from you could use that in the query, and or iterate over the deals pushing them into sub arrays, then adding the count.
Good luck with the client.
Mike