CapaJC
ServiceNow Employee
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
02-22-2013
02:28 PM
Sometimes a record has comments or worknotes, but it's not obvious if the form loads with another tab active. I decided to see how easy it'd be to make it more obvious.
Turns out it was pretty easy.
I created a "display" Business Rule on Incident that did the following - condition was !current.isNewRecord();
doIt();
function doIt() {
var gr = new GlideRecord("sys_journal_field");
gr.addQuery("element_id", current.sys_id);
gr.addQuery("element", "comments");
gr.query();
g_scratchpad.comments = gr.getRowCount();
gr.initialize();
gr.addQuery("element_id", current.sys_id);
gr.addQuery("element", "work_notes");
gr.query();
g_scratchpad.worknotes = gr.getRowCount();
}
Next I created an onLoad Client Script on Incident:
function onLoad() {
var e = $$(".tab_caption_text");
// Notes tab is the first one, so use e[0]
e[0].innerHTML = "" + g_scratchpad.comments + " Comments and " + g_scratchpad.worknotes + " Work Notes";
}
Worked a treat! When bringing up an Incident, the Notes form section tab label automatically changes to something like "2 Comments and 3 Work Notes", letting me know at a glance if I might need to switch to that tab.
Obviously a lot could go wrong, and these scripts need some protection, but this was just a 3-minute proof of concept (followed by a 10-minute writeup 😉 Thoughts on things to improve:
1) make sure the user has Read access to each field, change label accordingly
2) if Notes isn't the first form tab, it'll fail - protect against that
3) should use GlideAggregate vs. GlideRecord in the Business Rule
4) client script should make sure the scratchpad variables actually exist before doing anything with them
5) probably more I'm missing
6) "1 Comments" looks dumb - modify message to use the singular if only one
7) could build entire label on the server and pass that as the scratchpad variable
😎 Business Rule could use localized field labels, so a French user would see the French labels for "Comments" and "Work Notes"
9) you get the picture - bomb proofing something like this often takes 5x as long as the initial PoC!
- 731 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.