# Custom Code - submit form function

**URL:** <https://community.yeeflow.com/t/custom-code-submit-form-function/195>\
**Category:** Ask the community\
**Created:** [August 2, 2023, 12:59am UTC](https://community.yeeflow.com/t/custom-code-submit-form-function/195 "2023-08-02T00:59:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.yeeflow.com/sam/32/151_2.png) [@Sam](https://community.yeeflow.com/u/Sam)\
**Post date:** [August 2, 2023, 12:59am UTC](https://community.yeeflow.com/t/custom-code-submit-form-function/195/1 "2023-08-02T00:59:03Z")

</div>

Hi YeeFlow,

On form action, we have to use “Submit Form” step to submit the form, image below:

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

Now my question is, can I use [Custom code (Execute Script)](https://github.com/Yeeflow/custom-code) alone to submit the form? if yes, any code example?

Thank you!

---

<div class="post-metadata">

**Author:** ![Jason](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.yeeflow.com/jason/32/186_2.png) [@Jason](https://community.yeeflow.com/u/Jason)\
**Post date:** [August 2, 2023, 2:49am UTC](https://community.yeeflow.com/t/custom-code-submit-form-function/195/2 "2023-08-02T02:49:42Z")

</div>

What I mean is that you can add a “Submit Form” action after the custom code action

 ![微信图片_20230802104718](https://canada1.discourse-cdn.com/flex032/uploads/yeeflow/original/1X/df867ac322f712ccbf9003d2908e50408386fe4c.png)

---

<div class="post-metadata">

**Author:** ![Sam](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.yeeflow.com/sam/32/151_2.png) [@Sam](https://community.yeeflow.com/u/Sam)\
**Post date:** [August 2, 2023, 6:16am UTC](https://community.yeeflow.com/t/custom-code-submit-form-function/195/3 "2023-08-02T06:16:33Z")

</div>

Hi @Jason thank you for your quick reply.

I just found out why my custom code not running in sequence. (run “Execute Script” and “Submit Form” at the same time)

Since I have some dialog require user to click before submit.

I need to make the show dialog function become async function like belows:

```auto
const common = context.modules[MODULE_COMMON];
const { AkModal } = common;
//...
async function showDialog(contentMsg) {
            return await new Promise((resolve, reject) => {
                AkModal.confirm({
                    title: "Alert",
                    content: contentMsg,
                    onOk: () => {
                        let obj = {};
                        resolve(true);
                    },
                    onCancel: () => {
                        let obj = {};
                        resolve(false);
                    }
                });
              });
        }

```

And call this function with await.

```auto
await showDialog("msg1");

```

Thank you so much for your time and assistance in solving this problem.

---

<div class="post-metadata">

**Author:** ![Jason](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.yeeflow.com/jason/32/186_2.png) [@Jason](https://community.yeeflow.com/u/Jason)\
**Post date:** [August 2, 2023, 6:34am UTC](https://community.yeeflow.com/t/custom-code-submit-form-function/195/4 "2023-08-02T06:34:47Z")

</div>

1. You can use the Confirm dialog and the execution condition of the Submit Form is the value of the Confirm dialog.

2. The execution conditions of the “ Submit Form” are defined by yourself. (alert)

```auto
execute(context: CodeInContext, fieldsValues: any) { 
   const common = context.modules[MODULE_COMMON];
       const { AkModal } = common; 
       AkModal.confirm({
           title: "Alert",
           content: "1213131231",
           onOk: () => {
               let obj = {};
               context.setFieldValue("alert",false);  
           },
           onCancel: () => {
               let obj = {};
               context.setFieldValue("alert",true);  
               console.log("false")
           }
       }); 
  }

```

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