# Reading from rich text field of child entities in action button

**URL:** <https://community.fibery.io/t/reading-from-rich-text-field-of-child-entities-in-action-button/2190>\
**Category:** API & Programming\
**Created:** [November 6, 2021, 5:12am UTC](https://community.fibery.io/t/reading-from-rich-text-field-of-child-entities-in-action-button/2190 "2021-11-06T05:12:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seaotternerd](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@seaotternerd](https://community.fibery.io/u/seaotternerd)\
**Post date:** [November 6, 2021, 5:12am UTC](https://community.fibery.io/t/reading-from-rich-text-field-of-child-entities-in-action-button/2190/1 "2021-11-06T05:12:08Z")

</div>

I have a type that contains a collection of child entities (“Revisions”). Each revision has a rich text field called “Response”. I’m trying to make an action button that creates a document containing the contents of the “Response” field for all of the child “Revision” entities.

The following is my best attempt at making this work, but it fails on the second call to `fibery.getEntityById` with a 400 error. Does anyone have a solution?

```auto
<%
    const fibery = context.getService('fibery');
    const entityWithRevisions = await fibery.getEntityById(Entity.Type, Entity.Id, ['Revisions']);
    entityWithRevisions.Revisions.forEach((rev) => {
    const revWithExtraFields = await fibery.getEntityById("Papers/Revision", rev.Id, ['Response']);
   var desc = await fibery.getDocumentContent(revWithExtraFields.Response.Secret);
%>
**<%= rev.Name %>** : <%= desc %>
<% });%>

```

---

<div class="post-metadata">

**Author:** ![seaotternerd](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@seaotternerd](https://community.fibery.io/u/seaotternerd)\
**Post date:** [November 6, 2021, 4:46pm UTC](https://community.fibery.io/t/reading-from-rich-text-field-of-child-entities-in-action-button/2190/2 "2021-11-06T16:46:30Z")

</div>

Never mind, figured it out! The problem was using `await` inside the forEach function. Writing it in a script action was a helpful way to debug.

In case it’s helpful to anyone else, the following code works:

```auto
<%
    const fibery = context.getService('fibery');
    const entityWithExtraFields = await fibery.getEntityById(Entity.type, Entity.id, ['Revisions']);
    for (var i = 0; i < entityWithExtraFields.Revisions.length; i++) {
        var rev = entityWithExtraFields.Revisions[i];
        var revWithExtraFields = await fibery.getEntityById("Papers/Revision", rev.Id, ['Response']);
        var desc = await fibery.getDocumentContent(revWithExtraFields.Response.Secret);
%>

**<%= rev.Name%>** : <%= desc %>

<% } %>

```

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 14, 2022, 10:03am UTC](https://community.fibery.io/t/reading-from-rich-text-field-of-child-entities-in-action-button/2190/3 "2022-04-14T10:03:47Z")

</div>

Using rich text fields in automations without the need for scripting is now available:

> [@CHANGELOG: April 12 / Pinned State and Assignment fields, Read-only users can add Comments](https://community.fibery.io/t/changelog-april-12-pinned-state-and-assignment-fields-read-only-users-can-add-comments/2707):
>
> round_pushpin Pinned State and Assignment fields Panel navigation works great, but in many cases it demands more clicks to access fields. With this release you will always see State and Assignments in the main panel and can change values right there as well. The next step for us is to implement customization of pinned fields and make all kind of fields editable. zipper_mouth_face Read-only users can add Comments Free read-only users can add full co…

---

<div class="post-metadata">

**Author:** ![seaotternerd](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@seaotternerd](https://community.fibery.io/u/seaotternerd)\
**Post date:** [April 14, 2022, 4:07pm UTC](https://community.fibery.io/t/reading-from-rich-text-field-of-child-entities-in-action-button/2190/4 "2022-04-14T16:07:57Z")

</div>

Yay, awesome! Since I was writing a script anyway I ended up encoding a lot of additional logic here that I think probably does still require a script, but it’s great to be able to more easily work with rich text fields!

Side note, I really love how easy it is to mix markdown templating in with scripting.
