Too many fields on a form - Health scan report

VuchiV
Tera Contributor

Hello Everyone,

 

We have a health scan report ran on our instance and in one of the finding it is stated that there are some forms (not catalog forms) in which there are too many fields and asking to reduce the fields on the form for less than 30 fields either by creating different views or calculate fields.

 

There are 65 occurances mentioned in the report but the table details are not mentioned. Can you please let me know the way to get those form details from the system where there are more than 30 fields.

 

Thank You!!

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

In a recent health scan / Impact report, we have line items for the same, but were given the form name and count of fields in each instance.  If you don't have access to this level of detail, perhaps on a separate Sheet / tab in the file, here's how you can trace it back in a background/fix script.

 

The sys_ui_form table has a record for every table.  Each sys_ui_form record will have one or more sys_ui_form_section records.  This table has a field named sys_ui_section that is a reference to the sys_ui_section table.  We're almost there.  The sys_ui_section record has a sys_ui_element table record for every field in that section.  So what you need is a count of rows in the sys_ui_element table for each sys_ui_section of a sys_ui_form, by way of the sys_ui_form_section table.  Using this method includes things like .begin_split, .split, and .end_split that the health scan report does not count.  Here's a Fix Script I came up with starting with one known form as a proof of concept.  The count was equal to that on my report.

var count = 0;
var frmsecGr = new GlideRecord('sys_ui_form_section');
frmsecGr.addQuery('sys_ui_form', '147d8fa51bdd3410250052ca234bcb92');
frmsecGr.query();
while (frmsecGr.next()){
	//gs.print('in 1st while' + frmsecGr.sys_ui_section.caption)
	var secGr = new GlideRecord('sys_ui_section');
	secGr.addQuery('sys_id', frmsecGr.sys_ui_section);
	secGr.query();
	while (secGr.next()) {
		//gs.print ('in 2nd while ' + secGr.caption)
 		var eleGr = new GlideRecord('sys_ui_element');
 		eleGr.addQuery('sys_ui_section', secGr.sys_id);
		eleGr.addNullQuery('type');
 		eleGr.query();
 		if (eleGr.next()) {
 			count += eleGr.getRowCount();
		}
	}
}
gs.print('Fields on this form = ' + count);

 

@VuchiV were you able to test this awesome solution?

Hello @Brad Bowman  , the attached script did not work since it brings all the tables. Removing the types that contain split does not work the script. You have been able to identify the forms with fields greater than 30 that do not auto-calculate

That script showed that fields could be counted on a form in the same that is reported in the Health Scan.  To run this against all tables/forms using a configurable threshold, use this script:

var count = 0;
var maxFields = 30; //threshold / allowance
var frmGr = new GlideRecord('sys_ui_form');
frmGr.query();
while (frmGr.next()){
	count = 0;
	var frmsecGr = new GlideRecord('sys_ui_form_section');
	frmsecGr.addQuery('sys_ui_form', frmGr.sys_id);
	frmsecGr.query();
	while (frmsecGr.next()){
		var secGr = new GlideRecord('sys_ui_section');
		secGr.addQuery('sys_id', frmsecGr.sys_ui_section);
		secGr.query();
		while (secGr.next()) {
			var eleGr = new GlideRecord('sys_ui_element');
 			eleGr.addQuery('sys_ui_section', secGr.sys_id);
			eleGr.addNullQuery('type');
 			eleGr.query();
 			if (eleGr.next()) {
	 			count += eleGr.getRowCount();
			}
		}
	}
	if (count > maxFields) {
		gs.print('Fields on form ' + frmGr.name + ' = ' + count);
	}
}