⚙ Operations Hub

MCallies
Participant

Replacing Dates Portions of a Name

SOLVE

Okay, I'm looking to replace just a portion of a name and then populate it with something else. Essentially, at the end of our deal names, we have the create month and year of the deal, when a new renewal deal is created, I want to keep the name of the deal but replace the create month and deal with the renewal deal create month and year.

 

Example:

Deal Name - 01/21

and I want it to update to

Deal Name - 04/23

 

Tried a few options in OpsHub, but can't get anything to stick. Any suggestions from anyone doing something similar?

1 Accepted solution
KimM
Solution
Top Contributor

Replacing Dates Portions of a Name

SOLVE

Hi @MCallies ,

 

Should be pretty straightforward to generate the new name:

exports.main = async (event, callback) => {
var dealname = event.inputFields['dealname'];
dealname = dealname.split(' - ')[0];
var newcreatedate = new Date();
newcreatedate = new Intl.DateTimeFormat('en-GB', {year: "2-digit", month: "2-digit",}).format(newcreatedate);
var newdealname = dealname + ' - '+newcreatedate
  
  callback({
    outputFields: {
      newdealname: newdealname
    }
  });
}

 

This presumes you want to set the new date to the current date. If you're looking to set it as when the renewal date is actually due it might be a slightly different approach. Presuming it's 90 days from when the workflow is triggered you could just add 90 days to the date by adding this line:

newcreatedate.setDate(newcreatedate.getDate() + 90)

Then you can use the outputted 'newdealname' to either create a new record or update the existing record depending on what you want to achieve.

 

This is presuming that all of your deal names have the exact same structure of format to them, ie the deal name and date is separate by a ' - ' every time.

 

Let me know if any of this is unclear.

View solution in original post

4 Replies 4
MCallies
Participant

Replacing Dates Portions of a Name

SOLVE

Unfortunately not a one time thing, basically looking to set a workflow, so 90 days prior to deal expiring, a renewal deal is automatically created and the new info replaces the old.

0 Upvotes
KimM
Solution
Top Contributor

Replacing Dates Portions of a Name

SOLVE

Hi @MCallies ,

 

Should be pretty straightforward to generate the new name:

exports.main = async (event, callback) => {
var dealname = event.inputFields['dealname'];
dealname = dealname.split(' - ')[0];
var newcreatedate = new Date();
newcreatedate = new Intl.DateTimeFormat('en-GB', {year: "2-digit", month: "2-digit",}).format(newcreatedate);
var newdealname = dealname + ' - '+newcreatedate
  
  callback({
    outputFields: {
      newdealname: newdealname
    }
  });
}

 

This presumes you want to set the new date to the current date. If you're looking to set it as when the renewal date is actually due it might be a slightly different approach. Presuming it's 90 days from when the workflow is triggered you could just add 90 days to the date by adding this line:

newcreatedate.setDate(newcreatedate.getDate() + 90)

Then you can use the outputted 'newdealname' to either create a new record or update the existing record depending on what you want to achieve.

 

This is presuming that all of your deal names have the exact same structure of format to them, ie the deal name and date is separate by a ' - ' every time.

 

Let me know if any of this is unclear.

MCallies
Participant

Replacing Dates Portions of a Name

SOLVE

I got ya! Thanks.

karstenkoehler
Hall of Famer | Partner
Hall of Famer | Partner

Replacing Dates Portions of a Name

SOLVE

Hi @MCallies,

 

If this is a one-time effort, have you considered exporting your deals, making the name change in Excel quickly (using text to columns, for example), then re-importing the deals based on the record ID?

 

Best regards!

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.