Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
How to create an onSubmit Client Script to verify the mandatory variable is not empty - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • How to create an onSubmit Client Script to verify the mandatory variable is not empty
KB0622896

How to create an onSubmit Client Script to verify the mandatory variable is not empty


12117 Views Last updated : Dec 9, 2024 public Copy Permalink English (Original)
  • English (Original)
  • Japanese
KB Summary by Now Assist

Issue

This article details the steps to implement checking if a mandatory field is populated before order submission.

This is also the recommended solution for mandatory variables on Service Catalog RITM records intermittently created with empty values.

 

Release

All releases.

Resolution

  1. Navigate to Service Catalog > Catalog Policy > Catalog Client Scripts. A list of current custom catalog client scripts appears.
  2. Click New.
  3. Fill in the fields:
    • Active: Checked
    • Applies on a Catalog Item view: Checked
    • Type : onSubmit
      After selecting onSubmit, the script section will be pre-populated with function, do not delete this. 
    • Script:
      function onSubmit(){
         var mandatoryVar = g_form.getValue('<mandatory variable name>');
         if (mandatoryVar ==""){
            alert("<variable name> is mandatory. Please populate the variable and resubmit the request.");
         return false; }
      }
  4. Fill in the remaining fields as needed: 
    • Name : (any name)
    • Applies to : (does the mandatory field belong to a variable set or catalog item?)
    • Catalog item or Variable set: (select the catalog item or variable set that owns the mandatory field)
    • UI Type : (will this apply to policy apply to Desktop, Mobile or Both?)
    • Applies on Requested Items : (check if you want the policy to also apply on requested item view)
    • Applies on Catalog Tasks :(check if you want the policy to also apply on catalog task view)
  5. Click Submit.

Related Links

  • Catalog Client Scripts
  • Client Scripts

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

Attachments

Attachments

No attachments found

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.