logo

NJP

Setting custom column labels for Table export to Excel, CSV, XML, etc.

Import · Mar 10, 2022 · article

The world is big and weird requirements can be found quite often. Recently I got such. Basically, we needed to export data from tables, but with strictly predefined column labels.

By default, exporting to .xlsx file will put the ServiceNow column labels as column names of the exported excel file. When it comes to totally different custom column names, things become trickier.

One possible solution that I found is through database views.

For this example, I will use the ‘core_company’ table and will change the ‘street’ column to ‘STREET1’.

First step is to create Database view and add the ‘core_company’ table. It is important to remember the value that you put in the ‘prefix’ field, as you are going to need it later:

image

Second step is to navigate to System Definition -> Language File -> New

  • In Table put the database view you created
  • For Label put the desired name that will be set as a column header for the export
  • In the Element field put . Here in the example my prefix is ‘pref’, and the column from the ‘core_company’ table that I want to relabel is ‘street’, so I put ‘pref_street’
  • Save the record

image

Time to check if this works

Back to the database view – click ‘Try It’ related link.

image

We can see the street column labeled as we want: STREET1.

From now on, follow the standard way to export the data: right click on any column name, export, Excel.

image

Here is how the export looks like:

image

Please Mark Helpful if you find my content useful. Subscribe for more of my content. Thanks!

Martin Ivanov
2022 Community Rising Star image

View original source

https://www.servicenow.com/community/developer-articles/setting-custom-column-labels-for-table-export-to-excel-csv-xml/ta-p/2296899