# How to get data from Comments like author

**URL:** <https://community.fibery.io/t/how-to-get-data-from-comments-like-author/5957>\
**Category:** API & Programming\
**Created:** [March 10, 2024, 4:54pm UTC](https://community.fibery.io/t/how-to-get-data-from-comments-like-author/5957 "2024-03-10T16:54:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuri\_BC](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/yuri_bc/32/8803_2.png) [@Yuri\_BC](https://community.fibery.io/u/Yuri_BC)\
**Post date:** [March 10, 2024, 4:54pm UTC](https://community.fibery.io/t/how-to-get-data-from-comments-like-author/5957/1 "2024-03-10T16:54:48Z")

</div>

In the following script, I tried a method to get the comment author, but it does not work.  
What is the right way to get data of a comment?

```auto
const fibery = context.getService('fibery');
const threadsDb = 'Threads/Channel'; // 

async function updateEntityDescriptionWithComments(entityId) {
    // Fetch the current entity along with its comments
    const entityWithComments = await fibery.getEntityById(threadsDb, entityId, ['Comments']);
    let content = "";

    // Check if there are any comments to process
    if (entityWithComments.Comments && entityWithComments.Comments.length > 0) {
        // Iterate through each comment to concatenate the author's name and comment text
        for (const comment of entityWithComments.Comments) {
            // Fetch the author's name and comment content
            const authorName = comment['Author.Name'] || "Unknown Author";
            const commentContent = await fibery.getDocumentContent(comment['Document Secret'], 'md');

            // Combine the author name and comment content
            content += ` **${authorName}** : ${commentContent}\n\n`;
        }
    } else {
        console.log(`No comments found for entity ${entityId}.`);
        return;
    }

    // Fetch the current entity's Description to get its secret for updating
    const entityWithDescription = await fibery.getEntityById(threadsDb, entityId, ['Description']);
    if (entityWithDescription.Description && entityWithDescription.Description.Secret) {
        // Update the Description field with the aggregated comments content
        await fibery.setDocumentContent(entityWithDescription.Description.Secret, content, 'md');
        console.log(`Description for entity ${entityId} updated successfully with comments.`);
    } else {
        console.log(`Description field not found or not accessible for entity ${entityId}.`);
    }
}

async function processEntityComments() {
    try {
        if (!args.currentEntities || args.currentEntities.length === 0) {
            throw new Error('No current entity found.');
        }

        // Process each current entity 
        for (const currentEntity of args.currentEntities) {
            await updateEntityDescriptionWithComments(currentEntity.id);
        }
    } catch (error) {
        console.error(`Error processing comments for the entity: ${error.message}`, error);
    }
}

await processEntityComments();

```

---

<div class="post-metadata">

**Author:** ![Yuri\_BC](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/yuri_bc/32/8803_2.png) [@Yuri\_BC](https://community.fibery.io/u/Yuri_BC)\
**Post date:** [March 10, 2024, 6:20pm UTC](https://community.fibery.io/t/how-to-get-data-from-comments-like-author/5957/2 "2024-03-10T18:20:51Z")

</div>

I found it:

```auto
const commentEntity = await fibery.getEntityById('comments/comment', comment['Id'], ['Author']);
const authorName = commentEntity['Author']['Name'] || "Unknown Author";

```
