How to get the text of most recent comment

I’m trying to do something seemingly simple, but can’t figure it out. I’m trying to setup a field that gives me the text of the most recent comment. I have this formula as a start:

Comments.Sort([Creation Date]).Last()

but I get a red error that says “Formula result type cannot be Comment”. I’m trying to be able to grab this text via Zapier to drop it as a comment into a Discord channel. Maybe formula is not the way to go, but I don’t see a way to grab the most recent comment via Zapier either.

The comment is an object that has a number of fields on it, such at the text, the author, the timestamp, etc. Whereas presumably whatever you are passing this into is expecting a string?

1 Like

I suggest using an automation with a script, something like this:


The script is as follows:

const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {

    const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['Comments']);
    const comments = entityWithExtraFields['Comments'];
    const lastComment = comments.pop();
    const content = await fibery.getDocumentContent(lastComment['Document Secret']);
    await fibery.updateEntity(entity.type, entity.id, { 'Field': content });
}

where Field is the name of a text field where the last comment text will go.

1 Like