Blog

Exporting Field and Table Information

This article demonstrates some methods to export your field and table information to excel. By merging the Form Sections, Elements, and Labels into a single export, you can save some time when creating documentation or design documents.

I create two versions below. The quick "Scripts - Background" way of doing this, and the "New Application" version that is more refined.

Remember to try this out in your development environment first. It can take some time for the script to complete.

Version 1: Scripts - Background

This is a quick way to export table information without creating a new application:

  1. Elevate Role to security_admin

  2. In Scripts - Background run this statement:

    getFieldInfo();
    function getFieldInfo() {
    	var grSection = new GlideRecord('sys_ui_section');
    	grSection.query();
    	while (grSection.next()) {
    		var grSectionElement = new GlideRecord('sys_ui_element');
    		grSectionElement.addQuery('sys_ui_section',grSection.sys_id);
    		grSectionElement.OrderBy('position');
    		grSectionElement.query();
    		while (grSectionElement.next()) {
    			var grLabel = new GlideRecord('sys_documentation');
    			grLabel.addQuery('table',grSection.name);
    			grLabel.addQuery('element',grSectionElement.element);
    			grLabel.query();
    			if (grLabel.next()) {
    				gs.print('View: '+grSection.view.title+', Table: '+grSection.name+', Field Label: '+grLabel.label+', Field: '+grLabel.name);
    			} 
    		}
    	}
    }

     

  3. Copy the results.

  4. Open Excel and Paste the results

  5. In Excel, Use "Data > Text to Columns" to convert the commas to columns

Version 2: Create "Table Information" Application

This is a more elegant solution:

Add Field: View, Medium (100)
Add Field: Table, Medium (100)
Add Field: Field Label, Medium (100)
Add Field: Field, Medium (100)

  1. Tables & Columns:
    Create New Table
    Label: Table Information
    Table Name: u_table_information
    Create new application: false
    Create new module: true In application: System Definition

  2. Navigation Bar, type: u_table_information.form

  3. Right click > Personalize > Form Layout

  4. Create Script Includes:

    Script Includes:
    Name: setTableInformation
    Client Callable: true
    Script:
    function setTableInformation() {
    //Clear Table Information Table
    	var grTableInformation = new GlideRecord('u_table_information');
    	grTableInformation.query();
    	while (grTableInformation.next()) {
    		grTableInformation.deleteRecord();
    	}
    	gs.log('Deleted Table Information Table');
    //Set Table Information Table
    	var grSection = new GlideRecord('sys_ui_section');
    	grSection.query();
    	while (grSection.next()) {
    		var grSectionElement = new GlideRecord('sys_ui_element');
    		grSectionElement.addQuery('sys_ui_section',grSection.sys_id);
    		grSectionElement.OrderBy('position');
    		grSectionElement.query();
    		while (grSectionElement.next()) {
    			var grLabel = new GlideRecord('sys_documentation');
    			grLabel.addQuery('table',grSection.name);
    			grLabel.addQuery('element',grSectionElement.element);
    			grLabel.query();
    			if (grLabel.next()) {
    			var grTableInfoRow = new GlideRecord('u_table_information');
    			grTableInfoRow.initialize();
    				grTableInfoRow.u_view = grSection.view.title;
    				grTableInfoRow.u_table = grSection.name;
    				grTableInfoRow.u_field_label = grLabel.label;
    				grTableInfoRow.u_field = grLabel.name;
    				grTableInfoRow.insert();
    			} 
    		}
    	}
    }
  5. Create New Module: Set Table Information
    Script (from Arguments:)
    Icon: images/icons/js_validate.gif
    Arguments: setTableInformation();



Now you can use either of the methods to export the field and table information to excel. Awesome right?!

Mike