How to change date format for one field without impacting overall instance?

Ksnow
Tera Contributor

Hello, @Ankur Bawiskar @shloke04 @Amit Gujarathi 

 

Is it possible to change the date format from YYYY-MM-DD to DD-MM-YYYY for a single field on specific table without impact on other tables (overall instance)?

 

If yes, please share your suggestion. It would be highly appreciated.

 

Thanks a lot.

 

BR

5 REPLIES 5

Amit Gujarathi
Giga Sage
In this comprehensive tutorial, we delve deep into the world of ServiceNow GlideDateTime Format. Whether you're a seasoned pro or just starting with ServiceNow, this hands-on learning experience will equip you with the knowledge and use cases you need to excel. 🚀 🔥 Topics covered in this video:...

Thanks for your response.

 

In the video the explanation was regarding overall instance date format change, my question was can we do to one field on a particular table alone without disturbing other tables.

BR,

Vaishnavi Lathk
Mega Sage

Yes, in ServiceNow, you can change the date format for a single field on a specific table without impacting other tables or the overall instance. You can achieve this by configuring a Display Business Rule specifically for that field. Here's how:

  1. Identify the Field: Determine the field on the specific table for which you want to change the date format.

  2. Create a Display Business Rule: Go to System Definition > Business Rules and create a new Business Rule. Make sure to select the "Display" type.

  3. Set Conditions: Configure conditions to ensure the Business Rule only affects the specified field on the desired table.

  4. Script Action: Write a script action in the Business Rule to modify the date format when the field is displayed.

Here's a sample script that changes the date format from YYYY-MM-DD to DD-MM-YYYY for a field named my_date_field on the incident table:

(function executeRule(current, previous /*null when async*/) {
    // Check if the field is the one you want to format
    if (current.name == 'my_date_field') {
        // Change the date format from YYYY-MM-DD to DD-MM-YYYY
        var dateValue = current.getValue(); // Assuming 'my_date_field' is the field name
        var formattedDate = formatDate(dateValue); // Format the date

        // Set the formatted date back to the field
        current.setValue(formattedDate);
    }
})(current, previous);

// Function to format the date as DD-MM-YYYY
function formatDate(date) {
    var parts = date.split('-');
    return parts[2] + '-' + parts[1] + '-' + parts[0];
}
 
  1. Apply the Business Rule: Once you've created the Business Rule, set it to run on the display event for the specified table.

Regards,

Vaishnavi Lathkar

Sandeep Rajput
Tera Patron

@Ksnow I don't think if you can control the date format on your instance for a specific field, If you really wish to keep date in a different format then I recommend creating a normal string field and store the date in your desired format.