Use CustomCode of an ticket based workflow to get to latest added note

Hi,
I want to syncronize an added note including attachments to a different tool. For this I would like to use a custom code action.
But it is possible to grap the latest added note (and the related attachment) in the custom code to sent it to the other tool?

Thanks and best regards

Sven

Hi @Svenson :waving_hand:

It should be possible, yes. Here’s a flow you might like to consider:

  • Use the CRM Search API to find the most recent note

    (and any file attachment IDs)

    associated with the given record.

{
 "limit": 1,
 "filterGroups": [
 {
 "filters": [
 {
 "propertyName": "associations.{{OBJECT_TYPE}}",
 "operator": "EQ",
 "value": {{RECORD_ID}}
 }
 ]
 }
 ],
 "properties": [
 "hs_attachment_ids"
 ],
 "sorts": [
 {
 "propertyName": "hs_createdate",
 "direction": "DESCENDING"
 }
 ]
}

Where you’ll replace {{OBJECT_TYPE}} with the relevant object type (e.g. company) and {{RECORD_ID}} with the relevant record ID. You’ll also want to update the “properties” array according to your requirements. This should return no more than 1 result (either nothing or the most recently created Note that is associated with the given record).

  • Next, take the note attachment ID(s) from the response body JSON

    (results[0].properties.

    hs_attachment_ids)

    and get a “signed URL” per file to access it/them. More info can be found in the Files API documentation.

From there, you’ll just need to work out how to get this data into your target system :slightly_smiling_face:

I hope this proves useful. Please let me know if you have any follow-up questions.

Hi @zach_threadint,

Perfect, Thanks :ok_hand:
Where can I find a documentation which properties I can use?
I struggle everytime because I do not find the names like hs_note_body for example.

Best

Sven

Hi @Svenson :waving_hand:

I often use the Get All Properties API endpoint for this. One of the advantages of using the API for this is that you gain visibility on hidden properties. Another is you get access to properties of all object-types. Here’s a request template you might consider using:

The response should include all active (if archived parameter set to FALSE) or archived (if archived parameter set to TRUE) properties for the specified object-type. You can search the entire response for keywords of interest. You might also consider using a tool like JSONata to find properties of interest. For example, copy the entire response body JSON into the JSONata source input (left sidebar) and enter “results.label” into the query input (upper right panel). This should give you an easy to read array of all property labels within the response (lower right panel).

I hope this proves useful. Please let me know if you have any follow-up questions.

Perfect.
Thank you very much

Hi @zach_threadint,

Thank you very much. It works ;).
One other question. I need the text of the note as well, how I can get it?
Thank you and best regards

Sven

Hi @Svenson :waving_hand:

Try adding “hs_note_body” to the properties array of the first request. So your request body JSON might looking something like:

{
 "limit": 1,
 "filterGroups": [
 {
 "filters": [
 {
 "propertyName": "associations.{{OBJECT_TYPE}}",
 "operator": "EQ",
 "value": {{RECORD_ID}}
 }
 ]
 }
 ],
 "properties": [
 "hs_attachment_ids",
 "hs_note_body"
 ],
 "sorts": [
 {
 "propertyName": "hs_createdate",
 "direction": "DESCENDING"
 }
 ]
}

I hope this proves useful. Please let me know if you have any follow-up questions.