フォーム上で動作するUI macroについて

saitouwtr
Kilo Guru

フォーム画面上で動作する、フィールドに値を入力する以下UIアクション(クライアント)があります。

on click でg_form.setValue("field","value")

 

同様の動作でボタンをセクションに(自由に)配置したい要望があり、以下UI macroを設定し

 
UI macro:
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <button onclick="ui_macro();">ui_macro</button>
    <script>
        function ui_macro() {
            g_form.setValue("field", "value");
        };
    </script>
</j:jelly>
 
その後、UI formatter を用いてボタンをフォームに配置しクリックしたところ、
ボタン押下後に値がセットされた後、画面がNew Recordに遷移してしまいました。
希望の動作としては画面が遷移せず、保存もされないことです。
どのように実装すればよいでしょうか。よろしくお願いします。
1 件の受理された解決策

Ankur Bawiskar
Tera Patron
Tera Patron

@saitouwtr 

try this

Add type="button" to the button to prevent automatic form submission:

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
  <button type="button" onclick="ui_macro();">ui_macro</button>
  <script>
    function ui_macro() {
      g_form.setValue("field", "value");
    };
  </script>
</j:jelly>

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

元の投稿で解決策を見る

3件の返信3

Ankur Bawiskar
Tera Patron
Tera Patron

@saitouwtr 

try this

Add type="button" to the button to prevent automatic form submission:

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
  <button type="button" onclick="ui_macro();">ui_macro</button>
  <script>
    function ui_macro() {
      g_form.setValue("field", "value");
    };
  </script>
</j:jelly>

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

うまくいきました。ありがとうございました!

@saitouwtr 

Glad to help.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader