# Script Button to archive a linked record

**URL:** <https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775>\
**Category:** Ideas & Features\
**Tags:** automations\
**Created:** [July 8, 2021, 12:23am UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775 "2021-07-08T00:23:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Billiodeaux](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matthew_billiodeaux/32/3827_2.png) [@Matthew\_Billiodeaux](https://community.fibery.io/u/Matthew_Billiodeaux)\
**Post date:** [July 8, 2021, 12:23am UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/1 "2021-07-08T00:23:07Z")

</div>

Hello,

I am trying to create a button that moves a record reference in a table from one field (“User”) to another field (“Archived User”). I noticed this can be done without scripting through Fibery’s no-code automations, _ **but** _, there is a **conditional** that I need built into the button:

```auto
 if (User!=""){
      ... }

```

This is the code I have so far:

```auto
const api = context.getService("fibery");

for (const entity of args.currentEntities) {
    const UserIds = await api.getEntityById(entity.type, entity.id, [["User"]]);
    if (UserIds != null) {
        await api.updateEntity(entity.type, entity.id, { "Archived User": UserIds });
        await api.updateEntity(entity.type, entity.id, { "User": "[]" });
    }
}

```

And that code is throwing this **unexpected** exception…

```auto
Failed to execute action "Script": field.toLowerCase is not a function

```

Any help is appreciated!

> **Disclaimer**
>
> I am new to Fibery, and I know there may be better ways to structure my app, but please note my main purpose of posting this is to focus on learning the API/scripting portion of Fibery.
> 
> I have read these so far to construct the above code:
> 
> - [[✔️ DONE] Duplicate a record - #7 by Polina\_Zenevich](https://community.fibery.io/t/done-duplicate-a-record/386/7)
> - [Fibery](https://help.fibery.io/en/articles/3369412-action-buttons-old)  
> \*\* i know I probably should have read this one instead but didn’t find it until recently: [Fibery](https://help.fibery.io/en/articles/5169738-automated-action-buttons-new)
> - [fibery-community / Action Buttons · GitLab](https://gitlab.com/fibery-community/action-buttons)
> - [close-task-and-all-subtasks/readme.md · master · fibery-community / Action Buttons · GitLab](https://gitlab.com/fibery-community/action-buttons/-/blob/master/close-task-and-all-subtasks/readme.md)
> - [Code on top of your Fibery workspace - Fibery API](https://api.fibery.io/#action-buttons)
> - And though only tangentially related, this is listed also as it was extremely inciteful reading, the Fibery founders thoughts on low-coding automation… [Automations Concepts Overview](https://fibery.io/blog/automations-concepts-overview-for-no-code-tools/)

* * *

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [July 8, 2021, 8:42am UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/2 "2021-07-08T08:42:36Z")

</div>

Hi, Matthew

Thanks for letting know about your problem. Please find below explanation

1. Let’s assume I have setup with two users for entity as you described above. Every feature can have one **User** and one **Archived User**  

2. This is how the button script action can be configured to move User to Archived User  

The code is

```auto
const fibery = context.getService('fibery');
for (const entity of args.currentEntities) {
    const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['User']);
    if (entityWithExtraFields[`User`].id) {
        await fibery.updateEntity(entity.type, entity.id, {
            'Archived User': entityWithExtraFields[`User`].id,
            'User': null
        });
    }
}

```

Please let me know if I didn’t catch the issue correctly.

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![v3j](https://avatars.discourse-cdn.com/v4/letter/v/f07891/32.png) [@v3j](https://community.fibery.io/u/v3j)\
**Post date:** [July 8, 2021, 10:05pm UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/3 "2021-07-08T22:05:16Z")

</div>

What do I need to study to learn how to create such scripts? 🙂

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [July 9, 2021, 9:37am UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/5 "2021-07-09T09:37:47Z")

</div>

Hi, @v3j

We hope that there will be no need to learn scripts in the nearest future. No-code applications should make the life simpler. Will do our best to accomplish that.

Thanks,  
Aleh

---

<div class="post-metadata">

**Author:** ![v3j](https://avatars.discourse-cdn.com/v4/letter/v/f07891/32.png) [@v3j](https://community.fibery.io/u/v3j)\
**Post date:** [July 9, 2021, 10:42pm UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/6 "2021-07-09T22:42:12Z")

</div>

Hi Oleg,

No worries! I’m just really interested to learn how while waiting 🙂 What google keyword would you suggest for starters?

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [July 14, 2021, 7:24am UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/7 "2021-07-14T07:24:56Z")

</div>

Hi, @v3j

Thanks for your question. You may try suggestions from [how to become javascript developer - Google Search](https://www.google.com/search?q=how+to+become+javascript+developer&rlz=1C5CHFA_enBY919BY919&oq=how+to+become+javascript+&aqs=chrome.0.0l3j69i57j0j0i22i30l5.5300j0j7&sourceid=chrome&ie=UTF-8)

Good luck,  
Oleg

---

<div class="post-metadata">

**Author:** ![Matthew\_Billiodeaux](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matthew_billiodeaux/32/3827_2.png) [@Matthew\_Billiodeaux](https://community.fibery.io/u/Matthew_Billiodeaux)\
**Post date:** [July 21, 2021, 8:22pm UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/8 "2021-07-21T20:22:08Z")

</div>

Hello Oleg, and thank you for the reply. Very clear, and concise. Thanks for the included premise/assumption + picture + code. Also, apologies for the delayed reply. I work on this project in my spare time.

Regarding this assumption: Every feature can have one **User** and one **Archived User** …

I should have mentioned in my first post earlier that there can be multiple users for “UserIds” field. I see now that my naming convention is also misleading… I will update the original post! Sorry for the confusion!

---

<div class="post-metadata">

**Author:** ![Matthew\_Billiodeaux](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matthew_billiodeaux/32/3827_2.png) [@Matthew\_Billiodeaux](https://community.fibery.io/u/Matthew_Billiodeaux)\
**Post date:** [July 21, 2021, 8:31pm UTC](https://community.fibery.io/t/script-button-to-archive-a-linked-record/1775/9 "2021-07-21T20:31:14Z")

</div>

I ended up just restructuring my table and avoiding the whole array issue. 😃 thanks for your help!
