# Set value on one of the field in a Sub-List

**URL:** <https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154>\
**Category:** Ask the community\
**Created:** [April 17, 2023, 4:38am UTC](https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154 "2023-04-17T04:38:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_lee](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.yeeflow.com/steve_lee/32/157_2.png) [@steve\_lee](https://community.yeeflow.com/u/steve_lee)\
**Post date:** [April 17, 2023, 4:38am UTC](https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154/1 "2023-04-17T04:38:30Z")

</div>

HI, Is it possible to pre-set a value when every time user click the ‘Add’ button on a Sub-List?

I created a SubList as follow:

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/yeeflow/original/1X/462ad692b2bc1b0b4dcccac853917085036a6b00.png)

What I want to do is when user click Add: ![image](https://canada1.discourse-cdn.com/flex032/uploads/yeeflow/original/1X/4096e29188d0e52ea1d600b06b4cf04140a101d9.png)

I would like to set a value(e.g. current user name) on this field.

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/yeeflow/original/1X/297f1ffb95f6c93ebbca62e15c1e1ca2987df55d.png)

Is it possible on YeeFlow?

Thank you!

---

<div class="post-metadata">

**Author:** ![frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@frank](https://community.yeeflow.com/u/frank)\
**Post date:** [April 18, 2023, 10:51am UTC](https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154/2 "2023-04-18T10:51:14Z")

</div>

Steve,

Sorry this cannot be done by configuration. An idea is use a custom button to trigger an action. Action step execute a script to add new row to list with default value.

```auto
import { LIST_ROW_DELETE, MODULE_COMMON } from "./constants";

export class CodeInApplication implements CodeInComp {
    execute(context: CodeInContext, fieldsValues: any) {
        return new Promise((resolve, reject) => {
            
            const params = context.params;
            const common = context.modules[MODULE_COMMON];
            const fieldId = params["varId"];
            if (!fieldId) {
                alert("Please configure input parameter: varId");
                resolve(false);
            }
            const username = context.getFieldValue("field_name"); //variable store the name of current user

            let list = fieldsValues[fieldId] || [];

            list.push({ "field_1": username});

            context.setFieldValue(fieldId, [...list]); //form a new object otherwise the list will not be refreshed.

            resolve(true);
        });
    }

    requiredFields(params) {
        return [params["varId"]];
    }

    requiredModules() {
        return [];
    }

    description() {
        return "Add row of a list";
    }

    inputParameters() {
        return [{
            id: "varId",
            type: "string",
            desc: "Varaible ID of the list"
        }] as InputParameter[];
    }
}

```

Regards,  
Frank

---

<div class="post-metadata">

**Author:** ![steve\_lee](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.yeeflow.com/steve_lee/32/157_2.png) [@steve\_lee](https://community.yeeflow.com/u/steve_lee)\
**Post date:** [April 19, 2023, 8:12am UTC](https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154/3 "2023-04-19T08:12:25Z")

</div>

hi frank, seems the script can’t get the SubList information correctly?

here’s my code:

```auto
import { MODULE_COMMON, MODULE_REQUEST } from "./constants";

export class CodeInApplication implements CodeInComp {
  async execute(context: CodeInContext, fieldsValues: any) {
    return new Promise((resolve, reject) => {
      const params = context.params;
      console.log("params: ", params);

      const common = context.modules[MODULE_COMMON];

      const fieldId = params["message_box_id"];
      console.log("fieldId: ", fieldId);

      if (!fieldId) {
        alert("Please configure input parameter: varId");
        resolve(false);
      }

      // const username = context.getFieldValue("field_name"); //variable store the name of current user

      // let list = fieldsValues[fieldId] || [];
      // console.log('Lits: ', list);

      // list.push({ field_1: 'ha' });

      // context.setFieldValue(fieldId, [...list]); //form a new object otherwise the list will not be refreshed.

      resolve(true);
    });
  }

  requiredFields(params) {
    return [params["message_box_id"]];
  }

  requiredModules() {
    return [];
  }

  description() {
    return "Add row of a list";
  }

  inputParameters() {
    return [
      {
        id: "message_box_id",
        type: "string",
        desc: "Varaible ID of the list",
      },
    ] as InputParameter[];
  }
}

```

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/yeeflow/original/1X/31977c9dd7b5bf865df47ea5ea9ed3597fda8312.png)

Thank you

---

<div class="post-metadata">

**Author:** ![frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@frank](https://community.yeeflow.com/u/frank)\
**Post date:** [April 19, 2023, 9:09am UTC](https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154/4 "2023-04-19T09:09:09Z")

</div>

Hi Steve,

In your case, `message_box_id` should be the param value set for the custom code.

![image](https://canada1.discourse-cdn.com/flex032/uploads/yeeflow/original/1X/daac0c67bf25f31ad7c4d43ac519cce4071d3595.png)

---

<div class="post-metadata">

**Author:** ![steve\_lee](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.yeeflow.com/steve_lee/32/157_2.png) [@steve\_lee](https://community.yeeflow.com/u/steve_lee)\
**Post date:** [April 19, 2023, 9:38am UTC](https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154/5 "2023-04-19T09:38:02Z")

</div>

Hi frank, I am using “Action” here. I can’t find where to put this Input parameters. Am I doing this action incorrect?

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/yeeflow/original/1X/6ae82fdf100241c3936ae5f928637fc66eba86de.png)

---

<div class="post-metadata">

**Author:** ![frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@frank](https://community.yeeflow.com/u/frank)\
**Post date:** [April 19, 2023, 9:51am UTC](https://community.yeeflow.com/t/set-value-on-one-of-the-field-in-a-sub-list/154/6 "2023-04-19T09:51:37Z")

</div>

The input variable is defined at here

```auto
inputParameters() {
    return [
      {
        id: "message_box_id",
        type: "string",
        desc: "Varaible ID of the list",
      },
    ] as InputParameter[];
  }

```

It may be a litter bit delay in update, please save the step and then reopen the it to have a check.
