- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 10:10 AM
I'd want to share this fix with the community in hopes that it helps other Change Admins who are using the new Create a change request UI Page (sn_chg_model_ui_landing.do) and perhaps ServiceNow can fix this software defect in the future.
At the moment, the Change Request page will put the Standard Change Template (std_change_record_producer) records that follow the Change Types in a seemingly random order. Alphabetical based on name would be intuitive and preferable, but it seems to have no logic behind the order:
Behind the scenes, these cards are actually organized by sys_id, which might as well be random to the typical end-user.
Although admins don't have much control over Agent Workspace page sn_chg_model_ui_landing.do, I eventually tracked down the function to Script Include StandardChangeTemplate, which exists in an editable version and the Read-only SNC core. Function StandardChangeTemplateSNC.findAll() performs two queries, where the first one will .OrderBy() the name attribute, but the second query does not. This causes the results to be displayed in a random order, making the UI results less intuitive.
To fix this problem, append overwritten function StandardChangeTemplate.findAll() to the StandardChangeTemplate Script Include. The only additional line has been wrapped in comments:
StandardChangeTemplate.findAll = function(orderBy, textSearch, encodedQuery) {
orderBy = orderBy || ChangeProcess.NAME;
var changeRecordProducerGr = new GlideRecordSecure(StandardChangeTemplateSNC.CHANGE_RECORD_PRODUCER);
changeRecordProducerGr.addActiveQuery();
changeRecordProducerGr.addQuery("retired", false);
if (textSearch !== undefined && textSearch !== "undefined" && textSearch.trim() !== "")
changeRecordProducerGr.addQuery("name", "CONTAINS", textSearch).addOrCondition("short_description", "CONTAINS", textSearch);
if (encodedQuery !== undefined && encodedQuery !== "undefined" && encodedQuery.trim() !== "")
changeRecordProducerGr.addEncodedQuery(encodedQuery);
changeRecordProducerGr.orderBy(orderBy);
changeRecordProducerGr.query();
//Get a list of readable templates which might have user criteria in place if enabled
if ((gs.getProperty("com.snc.change_request.standard_change.use_user_criteria", 'true') === 'true') && (gs.getProperty("glide.sc.use_user_criteria", 'true') === 'true')) {
var readableRecords = [];
while (changeRecordProducerGr.next()) {
var sysId = changeRecordProducerGr.getUniqueValue();
if (new sn_sc.CatItem(sysId).canView())
readableRecords.push(sysId);
}
changeRecordProducerGr = new GlideRecord(StandardChangeTemplateSNC.CHANGE_RECORD_PRODUCER);
changeRecordProducerGr.addQuery('sys_id', "IN", readableRecords.join());
// START OF MODIFIED CODE THAT ENSURES CARDS ARE SORTED IN ORDER
changeRecordProducerGr.orderBy(orderBy);
// END OF MODIFIED CODE THAT ENSURES CARDS ARE SORTED IN ORDER
changeRecordProducerGr.query();
}
return changeRecordProducerGr;
};
Solved! Go to Solution.
- 1,060 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 10:18 AM
Since the code above is being treated as a "Question", I'm posting a TLDR down here as the answer:
- Two queries are performed in a function, the second one doesn't include orderBy to explicitly sort by Name
- The fix should be applied on the non-SNC version of the script include. If Script Include StandardChangeTemplate has not been modified, they can just append the code displayed above after line 13 (which is just a }); end of code block) or review and commit the linked Update Set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 10:18 AM
Since the code above is being treated as a "Question", I'm posting a TLDR down here as the answer:
- Two queries are performed in a function, the second one doesn't include orderBy to explicitly sort by Name
- The fix should be applied on the non-SNC version of the script include. If Script Include StandardChangeTemplate has not been modified, they can just append the code displayed above after line 13 (which is just a }); end of code block) or review and commit the linked Update Set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 12:47 AM
There is no real need to change the script, if you create a user preference for std_change_record_producer.db.order and set the value to name, tick the box for system, and you should be golden:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 07:04 AM
Hi ,
It was worked fine for preapproved tab. And I also want to do sorting for pinned tab and ALL Tab can you please suggest