クライアントスクリプトを使用して項目の入力必須化を行いたい

クライアントスクリプトを使用して項目の入力必須化を行いたい

いつもお世話になっております。
今成様や西尾様、松井様にはお話しておりますが、先日開催された「カスタム関数マスター講座 Vol.4」で、宿題として取り組んだもののうまくいかなかったクライアントスクリプトを投稿させていただきます。


【取り組んだテーマ】
自社の商談タブに設置しているサブフォームの項目「販売金額総額(税別)」で何らかの金額更新があったら、項目「外注総額_」をクライアントスクリプトで入力必須の項目にする。
 必須化の条件は、「販売金額総額(税別)」で「0」円よりも大きい数字(=1以上)が反映されたときとする。

(サンドボックス環境の商談タブ画面(データはダミーです))



【参照した情報と記述したコード】

(使用項目とAPI名)
・販売金額総額(税別)Quote_Amount
・外注総額_ TotalOutsourcing1

●テストコードその1

let quote_amount = ZDK.Page.getField('Quote_Amount'); // サブフォームの「販売金額総額(税別)」('Quote_Amount')をquote_amountと定義する
let quote_amount_value = ZDK.Page.getField(); // そのquote_amountの値をquote_amount_valueと定義する
log(quote_amount_value); // quote_amount_valueをログに出す?

let total_outsourcing1 = ZDK.Page.getField('TotalOutsourcing1'); // 外注総額_('TotalOutsourcing1')をtotal_outsourcing1と定義する

quote_amount.setValue('Quote_Amount'); // quote_amountに「販売金額総額(税別)」('Quote_Amount')の値をセットする?

if (quote_amount_value > 0) {   // もし、quote_amount_valueに0よりも大きい数字(=1以上)が入っていたら、
    total_outsourcing1 = ZDK.Form.Field.Mandate('TotalOutsourcing1'); // total_outsourcing1を入力必須項目とする
    total_outsourcing1.showError("「外注総額_は必須です。発生しない場合は0を入力してください");   // さらにtotal_outsourcing1にエラーメッセージを出す
} else {  // もし、quote_amount_fieldに0よりも大きい数字が入っていなければ(=0)、
    ZDK.Client.showMessage("見積書を作成する場合は「商談から見積書を作成する」ボタンをクリックしてください", { type: "info" });   // 画面に情報メッセージを出す ※本当は「何もしない」という処理を設定したい。
}

●テストコードその2 

var quote_amount_field = ZDK.Page.getField("quote_amount");  // サブフォームの「販売金額総額(税別)」("quote_amount")をquote_amount_fieldと定義する
quote_amount_field.setValue("quote_amount");  // quote_amount_fieldには、サブフォームの「販売金額総額(税別)」("quote_amount")の値を入れる
var total_outsourcing1_field = ZDK.Page.getField("TotalOutsourcing1");   // 「外注総額_」("TotalOutsourcing1")をtotal_outsourcing1_fieldと定義する

if (quote_amount_field > 0) {   // もし、quote_amount_fieldに0よりも大きい数字(=1以上)が入っていたら、
    total_outsourcing1_field = ZDK.Form.Field.Mandate('TotalOutsourcing1');    // total_outsourcing1_fieldを入力必須項目とする
    total_outsourcing1_field.showError("「外注総額_は必須です。発生しない場合は0を入力してください");    // さらにtotal_outsourcing1_fieldにエラーメッセージを出す
} else {    // もし、quote_amount_fieldに0よりも大きい数字が入っていなければ(=0)、
    ZDK.Client.showMessage("見積書を作成する場合は「商談から見積書を作成する」ボタンをクリックしてください", { type: "info" });   // 画面に情報メッセージを出す ※本当は「何もしない」という処理を設定したい。
}


(クライアントスクリプトのエディター画面)
*テストコードを2種類記述していますが、一方をコメントアウトして、それぞれでプレビューして挙動を確認しました。


*なお、岸本様のサンプルに「サブフォームの総額は項目変更の処理ができないため、ページが変わったらの条件で指定」との記載があったため、それに従い「ページの処理」に対して設定しています。(編集画面でのonChange)

【結果】
エディターツール上でエラーはカウントされないが、特に挙動もしない。

----------------------------

以上でございます。

Javascript未経験であるため、まずvarやletの使い分けなども理解できておらず、コメントで書き足しているコードの解釈なども誤っている箇所があるかと存じますが、挙動しない要因がどこにありそうか、ご意見をいただけますと幸いです。


何卒よろしくお願いいたします。



    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

                          Writer is a powerful online word processor, designed for collaborative work.

                            Zoho CRM コンテンツ






                              ご検討中の方

                                • Recent Topics

                                • Issue with skip_workflow Not Preventing Edit Workflow Trigger

                                  Hi Team, I am trying to upload a file to a form in Zoho Creator. However, during the upload, an edit workflow is being triggered. I want to prevent this workflow from running, so I have used the skip_workflow parameter as mentioned in the API documentation:
                                • Create Dashboard using data/tables from different workspaces

                                  Is it possible do create a Dashboard using different tables that are part of different Workspaces? 
                                • Este domínio já está associado a esta conta

                                  quando digitei meu domínio recebi essa mensagem que meu domínio estava associado a uma conta que eu nem faço idéia de quem seja. Como que faço pra resolver isso?
                                • Storage addon failed to upgrade

                                  Hi, I am trying to purchase addon storage, but i am getting upgrade failed error Sorry! We are unable to process your information. Please try again after some time. If the problem occurs again, please visit our Contact Us page to reach out to the appropriate
                                • no puedo recibir correos

                                  Hola, en la cuenta de la empresa desde hace unos tres días dejamos de recibir correos y no hemos realizado ningun cambio de configuracion, requerimos asistencia urgente por favor
                                • Default reminders on Emails

                                  I have seen that it is possible to set, for each email, a reminder when the email remains unresponded for some time. This is very useful, so useful that I would like to set it for all my emails, by default. Because an unanswered email usually requires
                                • NO PUEDO RECIBIR CORREOS EN MI CUENTA ZOHO MAIL

                                  LO QUE SI PUEDO HACER ES ENVIAR CORREOS PERO NO PUEDO RECIBIR CORREOS. Y LA CONFIGUIRACION DE MI DNS YA ESTA CORRECTA Y APUNTAN A ZOHO PERO AUN ASI NO PUEDO RECIBIR  NECESITO AYUDA URGENTE YA QUE EN MEXICO NO HAY FORMA DE COMUNICARNOS VIA TELEFONIA CON
                                • Send email is not authenticated

                                  Hi, I’m getting an error in Gmail, when receiving an email from my account in zoho, my email is already authenticated in my domain, and I don't know why I keep receiving this message... also testing in outlook, the message goes directly to "junk".
                                • Using Queries with dynamic parameters in Kiosk Studio

                                  Hi, I'm pretty new when it comes to developing within Zoho (I'm really a .NET developer), as it was just added to my responsibilities. For a new feature in the CRM, I'm trying to develop a Kiosk function to show a list of records (retrieved by the new
                                • Workflow Based on Manual Journal

                                  Manual journal entries are one of the few areas that cannot kick off a workflow automation in Zoho Books currently. I would propose considering adding that. My use case is that the payroll provider I use (a flavor of SurePayroll) has a Zoho Books automation
                                • Zoho sheets to crm and mapping

                                  i want to know more about mapping the contacts that i upload from the spreadsheet also couldnt able to understand flow
                                • Condition-based data sharing rules are now available in CRM

                                  Dear All,   We are excited to introduce a much awaited feature: condition-based data sharing rules. We'd love to explain more about this enhancement.   Specify record conditions in data sharing rules Data sharing rules enable you to share all the CRM
                                • Automatic Portal invite

                                  We have numerous customers we move through a blueprint in deals, when they get to a certain point we need to give them portal access, how can this be done through deluge or a workflow?
                                • Directly Edit, Filter, and Sort Subforms on the Details Page

                                  Hello everyone, As you know, subforms allow you to associate multiple line items with a single record, greatly enhancing your data organization. For example, a sales order subform neatly lists all products, their quantities, amounts, and other relevant
                                • Is it possible to trigger the review process when a record is edited?

                                  Hello, I need to trigger a review process whenever a field is updated to a specific value. This field is empty when the record is created and is only filled later. I know the approval process exists, but that's not what I'm looking for in this case. What
                                • 【Zoho CRM】ウィザード機能のアップデート

                                  ユーザーの皆さま、こんにちは。コミュニティチームの中野です。 今回は「Zoho CRM アップデート情報」の中からウィザード機能のアップデート をご紹介します。 今回のアップデートにより、ウィザードの「条件処理ルール」機能が改良され、以前の入力画面の項目を基に条件を設定できるようになりました。 これまでは条件設定が1つの画面内に限られていたため、画面間で情報を関連付ける際に、余分な項目を作成する必要がありました。 今回のアップデートにより、前の画面の情報を利用して次の画面に条件を適用できるため、設定がより効率的になります。
                                • Multiple date selection

                                  Hello, we want create app for our company. We need create tasks for our employers. For example - 1 employer have task every Friday the whole year. Second have task every Monday for 6 months. For simple way create Multiple date selection in date form
                                • Last payroll of the year gives me an error

                                  Trying to run the last payroll of the year. The payment doesn't get to the employee until 1/1/25, which is correct. However when I try to process it I get the following error: Tax calculation is not supported for the year 2025. Please change the Pay date.
                                • Partner with HDFC And Sbi Bank.

                                  Hdfc and sbi both are very popular bank if zoho books become partner with this banks then many of the zoho books users will benefit premium features of partnered banks.
                                • Set organization level access to Knowledge Base and manage duplicate article permalinks (with date appended to them)

                                  Hello everyone, We have introduced two important updates in the Knowledge Base module: Permissions - A new permission called "Admin access" has been introduced under module permission. Permalink alert - Users will be alerted when an article with the same
                                • Language Field on Contact Person-level

                                  Dear at Zoho Books, would it be possible for you to have a Field for 'Language' for the Contact Persons under a Company. In CRM and Bigin we could create a Custom Field (Dropdown) for this effect but without any present in Zoho Books we could never sync
                                • This domain is not allowed to add. Please contact support-as@zohocorp.com for further details

                                  I am trying to setup the free version of Zoho Mail. When I tried to add my domain, theselfreunion.com I got the error message that is the subject of this Topic. I've read your other community forum topics, and this is NOT a free domain. So what is the
                                • Zoho Books email notifications

                                  Hi, We are currently implementing Zoho books for our organisation. I have 2 questions. 1. Are we able to embed HTML into our emails to make them look as part of our business ? Branding is very big issue for us and i would like to make sure that all branding efforts are carried across into the notification emails.. 2. Is there a way to preview the notifications that are sent out to our customers so we can make sure the look and feel is as we require ? thanks
                                • Multiple templates (Settings > Email templates)

                                  Hi Zoho, We would like to have more options to select a template when sending an email in Zohosign. Currently we can only add 1 template per option: Is this possible? Kind regards, Tristan
                                • Add an action to set agent as a member of a team in zoho desk

                                  Hi, Please add an action to zoho flow to set agent as a member of a team in zoho desk (add to a team or remove from a team). Regards, Ram
                                • Zoho email setup in office365

                                  When i am trying to setup zoho mail setup using my domain in office365 and it is not working and it says that we couldn't log on to the incoming (IMAP) server and please check your email address and password and try again. I was able to login using my
                                • Plug Samples #12: Verify Customer Mobile Numbers with OTP to Avoid Spam Entries

                                  Hi Everyone! Verifying customer information is critical in business to filter out junk data and spammers. Whether it’s lead generation, appointment booking, or any other operation, ensuring quality data is essential for driving meaningful outcomes. A
                                • All notes disappeared

                                  I've been using the notebook app for over five years on my phone without being logged into an account. A few days ago I opened the app and all my notes had disappeared. Since then I tried restarting my phone, updating the app and logging into my account,
                                • I need help in setting up a script that works for my calling service

                                  Please i need your guidance and expertise in how to go about a particular scripting. You see, we are a call service that assists companies to receive calls for them, i need to create a system in my Zoho CRM whereby i will receive call from my already
                                • Cost Center accounting

                                  Hello all. We are looking at switching from MYOB to Zoho books. Love all the features in books - esp. CRM integration, but the big gap for us is the lack of cost-center accounting feature. Are there firm plans to develop this feature in Zoho Books? If
                                • Impuesto automatico en cotizaciones

                                  Buen dia Mi pregunta es como se puede poner alguna operacion para que las cotizaciones me salgan automaticamente con impuestos ya que uno al cargarla al final tienen que añadir el porcentaje de impuesto Saludos
                                • Formatting of Gantt Chart for PDF export

                                  Hi all, There really needs to be some improvements to the presentation of exported PDF Gantt Charts. An exported format is the way that most people on a project (other than the PM directly) will consume this data. The current PDF export options are lacking a lot of control. - I'd like to firstly have control over the export size of the PDFs (A4, A3 etc), Currently it seems arbitrary - very large aspect ratio print sizes. - Next i'd like to be able to specify the print date range, and scale (show
                                • How to Iterate a Function in Zoho Desk Workflow with Delay Between Calls?

                                  Hi everyone, I’m working on a function in Zoho Desk that searches for a specific ticket record. If the ticket is not found, I need to retry the search multiple times with a delay between each attempt until the ticket is located or a maximum number of
                                • タスクを問い合わせテンプレートに追加

                                  タスクを問い合わせテンプレートに自動で追加されるようにしたいです。どうしたらいいですか
                                • Placeholder for Agent Signature in Email Templates

                                  Dear Zoho Team, I hope this message finds you well. We currently face a limitation when designing email templates in Zoho Desk. While we can create email templates and include a footer at the end, the agent signature is always appended by default at the
                                • Custom Profile Agents Unable to Update Mandatory Phone Number in tickets under Zoho Desk

                                  Hi, While working in the Ticket module in Zoho Desk, agents with a custom profile are unable to update the Phone Number field (which is mandatory) under Account Information. The agents need to enter values such as "NA" or "Nil" in the field to close the
                                • Response Violation - Zoho Desk

                                  Hi Team, I just need an information regarding the zoho desk - Response Violation and how can we avoid the tickets from getting the tickets response violated.
                                • How to Replace an Assessment in a Job Opening on Zoho Recruit

                                  Hi everyone, I’m currently using Zoho Recruit and would like to replace the assessment linked to a specific job opening. I want to remove the existing assessment and add a new one. What is the best way to do this without losing any important data or affecting
                                • Updating existing values in a list

                                  Is it possible to update an existing value in a list? For example if I wanted to append text to an existing string value that I had previously added to a list is that possible? I'm able to extract the existing value (get() function) and append the additional text, but can't find a way to add the new value back to the list in the same index location. One work around I found was to delete the existing list entry and then add the new value, however this changes the index location to the last entry in
                                • Host not reachable

                                  Good morning. I have four mail accounts and they have been working well for years. Now, suddenly, I am unable to send any e-mails from any of them. I allways have this pop-up: Thank you. Regards. Luis Fernández
                                • Next Page