How to set default value for populating Current Date only?

AmarjeetN786
Kilo Contributor

procedure for configuring a default value in a ServiceNow field to populate the current date automatically when a new record is created. Provide a step-by-step explanation of the process, highlighting the relevant settings and options within ServiceNow that need to be utilized for this purpose

2 REPLIES 2

Satyapriya
Mega Sage

Hi @amarjeet,

        There are multiple ways you can a set a field value as current date.

      You can make it easily by :

      Right click on the respected field>Cinfigure Dictionary>Advanced View>Default Value.

      Check the 'Use Dynamic default'  check box  and add the Now(Date) in the dynamic default value field.

Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!

 

 

Danish Bhairag2
Tera Sage
Tera Sage

Hi @AmarjeetN786 ,

 

Certainly! Here is a step-by-step procedure for configuring a default value in a ServiceNow field to populate the current date automatically when a new record is created. In this example, I'll use a "Date" field as the target field:

 

### Step 1: Accessing the Form Designer

1. **Navigate to the Form:**

   - Log in to your ServiceNow instance.

   - Go to the application/module where you want to configure the default date field.

   - Open the form where you want to set the default date.

 

### Step 2: Access the Field Properties

2. **Access the Field Properties:**

   - In the form designer, locate the "Date" field where you want to set the default value.

   - Right-click on the field or click on the field properties icon (usually represented as a gear or wrench icon) to access the field properties.

 

### Step 3: Configure Default Value

3. **Set Default Value:**

   - In the field properties dialog, find the "Default Value" or "Default" section.

   - Select the option that allows you to specify a default value, usually a formula or a fixed value option.

   - Use the following ServiceNow GlideDateTime script to set the default value to the current date and time:

     ```

     javascript: gs.now()

     ```

   - Save your changes and exit the field properties dialog.

 

### Step 4: Validate and Save

4. **Validate and Save:**

   - Ensure the configuration is correct by checking the field properties.

   - Save the form configuration.

   - Test the default value by creating a new record in the specified form. The "Date" field should now automatically populate with the current date and time.

 

Please note that the exact labels and options might vary slightly based on the version of ServiceNow you are using, but the general process remains consistent. Additionally, if you want the default value to be only the date (without time), you can use the following script in the field default value configuration:

 

```

javascript: gs.dateGenerate()

```

 

This script will populate the field with the current date in the format "yyyy-MM-dd". Make sure to adjust the script according to your specific requirements and the expected date format.

 

Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish