Hi guys, what’s up?
It’s possible to extract the maximum date of a date property from a given property’s unique value. Would this be done through custom code?
Example: I have 3 different records of customized objects, but they have a property of the same value, equal, and another date property that are different, I would like to extract the maximum date of these 3 records.
Hey, @CarolineFscs
Thanks for the interesting question. I do not believe there is a single simple solution for this one. You have a few options, including:
Custom code and our APIs:
- Retrieve the Records using the Custom object endpoints using query params to filter based on your unique property value
- Filter and sort using custom code
Look at Custom Code Actions:
- Write a script using JavaScript or Python
- Fetch your records
- Apply filtering and maximum date logic
- And, possibly, update a record or trigger another action
If you have developer resources, you can set up Developer Test account to test this outside of your production portal.
Best,
Jaycee
Jaycee, I followed this path but it didn’t work because the return is {‘total’: 0, ‘results’: []}
import requests
headers = {
'authorization': 'key',
'Content-Type': 'application/json'
}
def main(event):
dataresposta = getDataResposta()
print(dataresposta)
def getDataResposta():
requestUrl = 'https://api.hubapi.com/crm/v3/objects/2-25689014/search'
data = {
"filterGroups": [
{
"filters": [
{
"value": "companyid",
"propertyName": "companyid",
"operator": "EQ"
},
{
"value": "NPS - Produto",
"propertyName": "pesquisa",
"operator": "EQ"
}
]
}
],
"properties": [
"data_resposta"
],
"sorts": [
{
"propertyName": "data_resposta",
"direction": "DESCENDING"
}
],
"limit": 1
}
response = requests.post(requestUrl, headers=headers, json=data)
return response.json()