- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2015 07:12 AM
I want to find a Duplicate field on Form in different section using script,
For Example Assigned To field can be added to two sections on incident form, So I want to find How many tables have such duplicate fields added on form through Script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2015 04:08 AM
Try this script:
var duplicatedViewElementAgg = new GlideAggregate('sys_ui_element');
duplicatedViewElementAgg.addQuery('type', '');
duplicatedViewElementAgg.addQuery('sys_ui_section.name', '!=', '');
duplicatedViewElementAgg.groupBy('element');
duplicatedViewElementAgg.groupBy('sys_ui_section.name');
duplicatedViewElementAgg.groupBy('sys_ui_section.view');
duplicatedViewElementAgg.addAggregate('COUNT');
duplicatedViewElementAgg.addHaving('COUNT', '>', '1');
duplicatedViewElementAgg.query();
while (duplicatedViewElementAgg.next()) {
var tableName = duplicatedViewElementAgg.getValue('sys_ui_section.name');
var view = duplicatedViewElementAgg.getValue('sys_ui_section.view');
var element = duplicatedViewElementAgg.getValue('element');
checkFormsForView(view, tableName, element);
}
function checkFormsForView(view, tableName, element) {
var formGR = new GlideRecord('sys_ui_form');
formGR.addQuery('name', tableName);
formGR.addQuery('view', view);
formGR.addQuery('sys_user', '');
formGR.query();
while (formGR.next()) {
var sectionIDs = getSectionIDs(formGR);
var hasNoSections = sectionIDs.length == 0;
if (hasNoSections)
continue;
var sectionNames = getSectionsNamesForElement(element, sectionIDs)
var isInMultipleSections = sectionNames.length >= 2;
if (isInMultipleSections)
gs.print('DupField: ' + tableName + '.' + element + ', View: ' + view + ' (Sections: ' + sectionNames + ')');
}
}
function getSectionsNamesForElement(element, sectionIDs) {
var sectionGR = new GlideRecord('sys_ui_element');
sectionGR.addQuery('element', element);
sectionGR.addQuery('sys_ui_section', 'IN', sectionIDs);
sectionGR.query();
var captions = [];
while (sectionGR.next()) {
var sectionCaption = sectionGR.sys_ui_section.getDisplayValue();
if (sectionCaption == '')
sectionCaption = 'DEFAULT'
captions.push(sectionCaption);
}
return captions;
}
function getSectionIDs(formGR) {
var sectionIDs = [];
var formSectionGR = new GlideRecord('sys_ui_form_section');
formSectionGR.addQuery('sys_ui_form', formGR.getUniqueValue());
formSectionGR.query();
while (formSectionGR.next()) {
sectionIDs.push(formSectionGR.sys_ui_section + '');
}
return sectionIDs;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2015 07:37 AM
Let X = whatever field you're searching for.
Search the sys_ui_element table where element = x.
sys_ui_element.sys_ui_section tells you what section of the form its on.
sys_ui_element.sys_ui_section.name is the table.
sys_ui_element.sys_ui_section.view is the specific form view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2015 07:54 AM
Thanks rfedoruk
But I want to know how can I access sections using script and fields on it. Feeling annoying. Tough Task for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2015 08:23 AM
What do you want the end result of the script to be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2015 08:28 AM
section.field name for table