# \[Quick guide\] Assign all children to me

**URL:** <https://community.fibery.io/t/quick-guide-assign-all-children-to-me/2160>\
**Category:** API & Programming\
**Created:** [October 28, 2021, 2:28pm UTC](https://community.fibery.io/t/quick-guide-assign-all-children-to-me/2160 "2021-10-28T14:28:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haslien](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/haslien/32/493_2.png) [@Haslien](https://community.fibery.io/u/Haslien)\
**Post date:** [October 28, 2021, 2:28pm UTC](https://community.fibery.io/t/quick-guide-assign-all-children-to-me/2160/1 "2021-10-28T14:28:52Z")

</div>

I didn’t see an easy way to do this with the current buttons, so I made it with code.

# Demo

[https://i.thevirt.us/10/28y3O.mp4](https://i.thevirt.us/10/28y3O.mp4)

# Video of setup process

[https://i.thevirt.us/10/U0p0w.mp4](https://i.thevirt.us/10/U0p0w.mp4)

The App name is copied from the one that has the Child, since the child doesn’t necessarily have to be from the same app (_hence the redundant navigation to child for App name in the video_).  
Clear the example code generated, paste this in your Script and fill it out:

```js
const childFieldName = "NAME_OF_CHILD_RELATION";
const foreign = {
    appName: "CHILD_APP_NAME",
    typeName: "CHILD_TYPE_NAME"
}

const fibery = context.getService('fibery');
for (const entity of args.currentEntities) {
    const withAllChildren = await fibery.getEntityById(entity.type, entity.id, [childFieldName]);
    if (!withAllChildren[childFieldName].length) return;

    await Promise.all(
        withAllChildren[childFieldName]
        .map(item => 
            fibery.assignUser(`${foreign.appName}/${foreign.typeName}`, item.Id, args.currentUser.id)
            )
        );
}

```
