Removing duplicate icons in the Mobile UI
Seeing double? Double mobile icons that is. Users on a Eureka or Fuji release may be experiencing duplicate icons in their ServiceNow instances on mobile. Icons such as Help, Service Catalog, My Incidents, Contacts, Follow-up, and High Priority, may appear more than once when you are in the mobile UI. The issue is caused by the unintentional creation of duplicate records on the following tables:
- sys_ui_home_favorite table
- sys_ui_home_section table
- label records
When users are removed the records are not getting cleaned up so duplicates are generated in the system.
You may experience upwards of 1,000 duplicate icons if things get messy. Now, that is a sight for sore eyes. Well I've got two troubleshooting paths that will help you remove the home favorite records, home section records, and label records.
To revert your icons to their unique buttons:
Delete the sys_ui_home_favorite records:
- Navigate to System Mobile UI > Home Page Favorites.
- Filter the list for records where the User field matches the affected user. The filtered list shows the user's favorites. There may be multiple copies of each favorite.
- Delete the extra records.
Delete the sys_ui_home_section records:
- Navigate to System Mobile UI > Home Page Sections.
- Filter the list for records where the User field matches the affected user. The filtered list shows the user's sections. There may be multiple copies of each section.
- Delete the extra records.
Delete the label records:
- Navigate to System Definition > Tags. (Tags were originally called labels. While the terminology has changed, these records are still stored on the "label" table).
- Filter the list for records where the Owner field matches the affected user. The filtered list shows the user's tags. There may be multiple copies of each tag.
- Delete the extra records.
This step can also be done by simply running a script in the Scripts- Background.
(function() {
deleteDuplicates('sys_ui_home_section', ['user', 'table', 'label']);
deleteDuplicates('sys_ui_home_favorite', ['user', 'table', 'label', 'icon']);
deleteDuplicates('label', ['owner', 'name', 'short_description', 'background_color', 'color', 'icon']);
// table :: string, fields :: [string]
function deleteDuplicates(table, fields) {
var current = new GlideRecord(table),
prior = new GlideRecord(table);
// ordering will not work on records created by snc hop access due to missing sys_user records
current.addQuery('sys_created_by', 'DOES NOT CONTAIN', '@snc');
prior.addQuery('sys_created_by', 'DOES NOT CONTAIN', '@snc');
// ditch if there are no fields
if(fields.length < 1) {
gs.log('deleteDuplicates requires at least one field');
return false;
}
// order by array of fields passed in
for(i = 0; i < fields.length; i++) {
current.orderBy(fields[i]);
prior.orderBy(fields[i]);
}
- current.query();
prior.query();
// bail if the query returns nothing
if(!current.hasNext()) {
gs.log('no records returned');
return true;
}
// current will always be one ahead of prior
current._next();
// loop through...
var dups = 0;
while(current._next() && prior._next()) {
var i;
// ...and compare adjacent records
for(i = 0; i < fields.length; i++) {
if( current.getValue(fields[i]) != prior.getValue(fields[i]) ) break;
}
if(i == fields.length) {
//gs.log('duplicate detected: current[' + current.sys_id + '] prior[' + prior.sys_id + ']');
//gs.log('deleting [' + prior.sys_id + ']');
prior.deleteRecord();
dups++;
}
}
- gs.log("Removed " + dups + " duplicates from " + table);
return true;
}
})();
This business rule can also be loaded into the affected instance as an XML file to prevent a re-occurrence of the issue until a fix is released. You can download the file from here.
To Import records as XML data:
- Sign in as an admin to the instance that should receive the data.
- Navigate to any list in the system.
Any list can be used because the XML file contains the destination table name for the records. - Right-click the list header and select Import XML.
- In the import screen, click Choose File and select the previously exported XML file.
- Click Upload.
Now that you've fixed your duplicate icons you can cancel that eye appointment use the mobile app with ease!
https://www.servicenow.com/community/developer-blog/removing-duplicate-icons-in-the-mobile-ui/ba-p/2269719