Last active
January 17, 2023 18:28
-
-
Save HubSpotHanevold/472387da34276ee2a1cff34bebefcb71 to your computer and use it in GitHub Desktop.
This custom coded action takes the most recent value from the record type in question then adds a value to that previous amount. Use this code for auto incrementing records.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var axios = require('axios'); | |
const auth = 'Bearer ' + process.env.ADD_YOUR_SECRET_KEY_NAME_HERE; | |
exports.main = async (event, callback) => { | |
var data = JSON.stringify({ | |
"filterGroups":[ | |
{ | |
"filters":[ | |
{ | |
"propertyName": "property_auto_incrementing", | |
"operator": "HAS_PROPERTY" | |
} | |
] | |
} | |
], | |
"sorts": [ | |
{ | |
"propertyName": "property_auto_incrementing", | |
"direction": "DESCENDING" | |
} | |
], | |
"properties": [ "property_auto_incrementing" ] | |
}); | |
// CHANGE DEAL TO THE OBJECT TYPE YOU'RE USING IN THE URL BELOW | |
var config = { | |
method: 'post', | |
url: 'https://api.hubapi.com/crm/v3/objects/deals/search', | |
headers: { | |
'content-type': 'application/json', | |
'Authorization': auth | |
}, | |
data : data | |
}; | |
axios(config) | |
.then(function (response) { | |
// console.log(JSON.stringify(response.data)); | |
let result = JSON.stringify(response.data); | |
const obj = JSON.parse(result); | |
// console.log(obj); | |
let most_recent_value = obj.results[0].properties.property_auto_incrementing; | |
// CONVERT THE STRING TO NUMBER (MAY NOT BE NEEDED) | |
let most_recent_value_num = Number(most_recent_value); | |
// YOU CAN CHANGE THE AUTO INCREMENTING AMOUNT BELOW - AS NEEDED | |
let next_value = most_recent_value_num + 1; | |
callback({ | |
outputFields: { | |
most_recent_value: most_recent_value, | |
next_value: next_value | |
} | |
}); | |
}) | |
.catch(function (error) { | |
console.log(error); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment