Dow to add 'active' field on a table

MariaVitorS
Tera Contributor

Hi guys, what's up?
I'm working on the customer_account table and I'd like to know how I can:

  1. Create a field to indicate whether the record is active or not (for example, an "Active?" field);
  2. Configure so that deactivated records don't appear in lists automatically.

Could someone advise me on how to do this? Thanks in advance!

1 ACCEPTED SOLUTION

_ukasz Rybicki
Giga Guru

Problem Name: Add Active Field and Hide Inactive Records


General Solution Proposal:
To manage active and inactive records in the customer_account table, add a Boolean field named Active. Then, implement a "Before Query" Business Rule to automatically filter out inactive records from list views, ensuring only active records are displayed by default.


Detailed Step-by-Step Solution:

  1. Add the 'Active' Field:

    • Navigate to System Definition > Tables.

    • Search for and open the customer_account table.

    • In the Columns section, click New.

    • Set the following:

      • Column label: Active

      • Column name: active

      • Type: Boolean

      • Default value: true

    • Click Submit to save the new field.

  2. Create a 'Before Query' Business Rule:

    • Go to System Definition > Business Rules.

    • Click New to create a new Business Rule.

    • Configure the Business Rule:

      • Name: Filter Active Customer Accounts

      • Table: customer_account

      • Advanced: Checked

      • When: Before

      • Insert: Unchecked

      • Update: Unchecked

      • Delete: Unchecked

      • Query: Checked

    • In the Script section, enter:

      // Filter to show only active records
      if (!gs.hasRole('admin')) {
        current.addQuery('active', true);
      }
    • Click Submit to save the Business Rule.

    Note: This script ensures that only users without the 'admin' role see active records by default. Admins can view all records.


Example Use Case:
A ServiceNow administrator wants to prevent end-users from seeing inactive customer accounts in list views. By adding an 'Active' field and implementing a Business Rule, inactive records are hidden from standard users, maintaining data relevance and cleanliness.


Prepare for discussion on the solution:

  • Why use a Business Rule instead of ACLs?
    Business Rules are suitable for modifying query behavior before data retrieval, ensuring inactive records are excluded from list views without affecting form access controls.

  • Can this approach be extended to reference fields?
    Yes, by adding a reference qualifier to reference fields pointing to customer_account, you can ensure only active records are selectable.

  • What if different roles require different visibility?
    Modify the Business Rule script to include role checks, displaying records based on user roles.


Sources:

  1. What is the best way to hide a record? - ServiceNow Community
    Discusses adding an 'Active' field and using reference qualifiers to filter records.

  2. Unable to hide records from list view - ServiceNow Community
    Suggests using a 'Before Query' Business Rule to filter records in list views.

  3. Hide Column from List View - ServiceNow Community
    Explains using ACLs to control visibility of fields in list views.


Final Version:
By adding an 'Active' Boolean field to the customer_account table and implementing a 'Before Query' Business Rule, you can effectively manage the visibility of active and inactive records in list views. This approach ensures that users see only relevant, active records by default, enhancing data management and user experience.

View solution in original post

4 REPLIES 4

jcmings
Mega Sage

To accomplish your first ask, you need to create a field titled "Active" of type "True/False" on your table. To find where to do this, go to your list view, click on the three dots next to a column header, and choose Configure > Table.

jc21_0-1746553606950.png

 

You'll then open the Columns related list and click New to create your field.


Note: I am not familiar with the Customer Account table. It's possible there is already an Active field. To find this out, instead of creating a new column, first search the columns for the field "Active".

jc21_1-1746553644538.png

 

 

To accomplish your second ask, you'll need to update the Module that links to your table. Go to System Definition > Modules and locate the module that users use to go to your list of records. In the Link Type section, add the condition for Active is true.

 

jc21_2-1746553775385.png

 

Bert_c1
Kilo Patron

As admin user, goto the custer_account table and add a new column as below

 

Screenshot 2025-05-06 134440.png

 

Next, create a business rule as shown below

Screenshot 2025-05-06 204332.png

 

You could always just filter the list 'u_active=true'.

 

Filters

 

_ukasz Rybicki
Giga Guru

Problem Name: Add Active Field and Hide Inactive Records


General Solution Proposal:
To manage active and inactive records in the customer_account table, add a Boolean field named Active. Then, implement a "Before Query" Business Rule to automatically filter out inactive records from list views, ensuring only active records are displayed by default.


Detailed Step-by-Step Solution:

  1. Add the 'Active' Field:

    • Navigate to System Definition > Tables.

    • Search for and open the customer_account table.

    • In the Columns section, click New.

    • Set the following:

      • Column label: Active

      • Column name: active

      • Type: Boolean

      • Default value: true

    • Click Submit to save the new field.

  2. Create a 'Before Query' Business Rule:

    • Go to System Definition > Business Rules.

    • Click New to create a new Business Rule.

    • Configure the Business Rule:

      • Name: Filter Active Customer Accounts

      • Table: customer_account

      • Advanced: Checked

      • When: Before

      • Insert: Unchecked

      • Update: Unchecked

      • Delete: Unchecked

      • Query: Checked

    • In the Script section, enter:

      // Filter to show only active records
      if (!gs.hasRole('admin')) {
        current.addQuery('active', true);
      }
    • Click Submit to save the Business Rule.

    Note: This script ensures that only users without the 'admin' role see active records by default. Admins can view all records.


Example Use Case:
A ServiceNow administrator wants to prevent end-users from seeing inactive customer accounts in list views. By adding an 'Active' field and implementing a Business Rule, inactive records are hidden from standard users, maintaining data relevance and cleanliness.


Prepare for discussion on the solution:

  • Why use a Business Rule instead of ACLs?
    Business Rules are suitable for modifying query behavior before data retrieval, ensuring inactive records are excluded from list views without affecting form access controls.

  • Can this approach be extended to reference fields?
    Yes, by adding a reference qualifier to reference fields pointing to customer_account, you can ensure only active records are selectable.

  • What if different roles require different visibility?
    Modify the Business Rule script to include role checks, displaying records based on user roles.


Sources:

  1. What is the best way to hide a record? - ServiceNow Community
    Discusses adding an 'Active' field and using reference qualifiers to filter records.

  2. Unable to hide records from list view - ServiceNow Community
    Suggests using a 'Before Query' Business Rule to filter records in list views.

  3. Hide Column from List View - ServiceNow Community
    Explains using ACLs to control visibility of fields in list views.


Final Version:
By adding an 'Active' Boolean field to the customer_account table and implementing a 'Before Query' Business Rule, you can effectively manage the visibility of active and inactive records in list views. This approach ensures that users see only relevant, active records by default, enhancing data management and user experience.

_ukasz Rybicki
Giga Guru

Problem Name: Managing Active Status in customer_account Table 🟢🔴


General Solution Proposal:

To manage active and inactive records in the customer_account table, add a Boolean field named Active. Then, implement a "Before Query" Business Rule to automatically filter out inactive records from list views, ensuring only active records are displayed by default.


Detailed Step-by-Step Solution:

  1. Add the 'Active' Field:

    • Navigate to System Definition > Tables.

    • Search for and open the customer_account table.

    • In the Columns section, click New.

    • Set the following:

      • Column label: Active

      • Column name: active

      • Type: Boolean

      • Default value: true

    • Click Submit to save the new field.

  2. Create a 'Before Query' Business Rule:

    • Go to System Definition > Business Rules.

    • Click New to create a new Business Rule.

    • Configure the Business Rule:

      • Name: Filter Active Customer Accounts

      • Table: customer_account

      • Advanced: Checked

      • When: Before

      • Insert: Unchecked

      • Update: Unchecked

      • Delete: Unchecked

      • Query: Checked

    • In the Script section, enter:

      // Filter to show only active records
      if (!gs.hasRole('admin')) {
        current.addQuery('active', true);
      }
    • Click Submit to save the Business Rule.

    Note: This script ensures that only users without the 'admin' role see active records by default. Admins can view all records.


Example Use Case:

A ServiceNow administrator wants to prevent end-users from seeing inactive customer accounts in list views. By adding an 'Active' field and implementing a Business Rule, inactive records are hidden from standard users, maintaining data relevance and cleanliness.


Prepare for Discussion on the Solution:

  • Why use a Business Rule instead of ACLs?
    Business Rules are suitable for modifying query behavior before data retrieval, ensuring inactive records are excluded from list views without affecting form access controls.

  • Can this approach be extended to reference fields?
    Yes, by adding a reference qualifier to reference fields pointing to customer_account, you can ensure only active records are selectable.

  • What if different roles require different visibility?
    Modify the Business Rule script to include role checks, displaying records based on user roles.


Sources:

  1. Dow to add 'active' field on a table - ServiceNow Community
    Link
    Discusses adding an 'Active' field and using a Business Rule to filter records in list views.

  2. What is the best way to hide a record? - ServiceNow Community
    Link
    Suggests adding an 'Active' field and using reference qualifiers to filter records.

  3. Hide Column from List View - ServiceNow Community
    Link
    Explains using ACLs to control visibility of fields in list views.


If you need assistance implementing this solution or have further questions, feel free to ask! 😊