I
‘ve answered several questions in the past about the functionality of lock icons in Service-now. Lock icons appear on glide_list and URL fields. The most-common example is the ‘Watch list’ field on the task table. Service-now provides some system properties to manage the default lock appearance of these field types. There are times when a global system property doesn’t really meet the need you have however, and you need to lock or unlock these fields automatically using script. In this article I’ll explain how I’ve done these types of things before.
System Properties
First, the system properties. These can be found by navigating to ‘System Properties -> UI Properties’. Obviously they’re very simple to set, but they will apply system-wide, which limits their usefulness in many cases.
- ‘Glide lists start out locked’ (glide.ui.glide_list.start.locked) – Controls the default lock behavior of ALL glide_list fields on form load
- ‘Unlock empty URL fields on form load’ (glide.ui.unlock_empty_url) – Controls the default lock behavior of all empty URL fields on form load
Client Scripts
For more control over the lock/unlock behavior of these field types, you’ll need to use client scripts or UI policies. Here are some examples…
Lock/Unlock glide_list Fields
Lock glide_list field named ‘watch_list’ (Replace every instance of ‘watch_list’ with the name of your field and every instance of ‘incident’ with the name of the table the script runs against)
Unlock glide_list field named ‘watch_list’ (Replace every instance of ‘watch_list’ with the name of your field and every instance of ‘incident’ with the name of the table the script runs against)
Lock/Unlock URL Fields
Lock URL field named ‘u_url’ (Replace every instance of ‘u_url’ with the name of your field and every instance of ‘incident’ with the name of the table the script runs against)
Unlock URL field named ‘u_url’ (Replace every instance of ‘u_url’ with the name of your field and every instance of ‘incident’ with the name of the table the script runs against)
Advanced Custom Locking Scripts
Show/hide fields based on lock/unlock
This onLoad client script shows/hides the ‘short_description’ field when you click the lock/unlock icons on the ‘watch_list’ field. What you have to do to get this to work is define a custom event handler in your ‘onLoad’ client script. In this case, there is a built-in ‘onclick’ event that you need to access. You can see what the IDs and events are by using a DOM inspector like firebug in a Firefox browser. You can customize which field gets hidden by modifying the ‘g_form.setDisplay’ lines in the script below.
//Get the control of the unlock icon
var unlockControl = g_form.getControl('watch_list_unlock');
//Set its onclick method
unlockControl.onclick = unlockClick;
//Get the control of the lock icon
var lockControl = g_form.getControl('watch_list_lock');
//Set its onclick method
lockControl.onclick = lockClick;
}
function unlockClick() {
g_form.setDisplay('short_description', false);
unlock(this, 'incident.watch_list', 'incident.watch_list_edit', 'incident.watch_list.nonedit');
}
function lockClick(){
g_form.setDisplay('short_description', true);
lock(this, 'incident.watch_list', 'incident.watch_list_edit', 'incident.watch_list_nonedit', 'select_0incident.watch_list', 'incident.watch_list_nonedit');
}
Creating a custom lock icon for any form element
You can also add custom lock icons to other form elements. One example I’ve written in the past is a lock icon situated next to the ‘Category’ field on an incident form. Clicking the lock icon displays or hides other categorization fields. Check out the ‘Adding a UI Macro to a Non-reference Field’ article for more information.
Awesome! Works perfect!
I just used this, and it works great. This helped me integrate some customizations I wanted very nicely. Nice explanation.
In regards to the basic client script example above, it appears that the code has changed every so slightly when I view the source HTML of a form and find the call to the unlock function. I found it is as easy to call the onclick()
gel('incident.watch_list_list_unlock').onclick();
Awesome! That’s much easier than the other way. I’ve updated the article above with this method.
Hi,
I made property change to keep variable unlocked for Glide list. I have a variable in the form of type glide_list, it is working fine and now when I open form I can see variable is unlocked.
Now I an thinking why I am not getting “slushbucket” button when I first open the form. If I click on any new request I can’t see slushbucket button just above lock button. But once I save the request I can see slushbucket button above the lock button.
Is there is any system property I need to turn on to make slushbucket option available in form? OR Is there is any option where I can just get slushbucket only instead of glide list?
Regards,
ND
There’s nothing you can do about that unfortunately. That’s just how list fields are designed. You can request an enhancement through ServiceNow support.
So, is this perhaps something that also does not work in Berlin? I just tried the simple method of
gel(‘incident.watch_list_lock’).onclick();
Looks like yet another Berlin client scripting casualty. I’ve updated the scripts above. Try just ‘click’ instead of ‘onclick’.
If you are in Berlin release, use the dictionary attribute ‘start_locked=false’ on your field to expand the glide_list all the time.
Nice. Thanks for sharing.
The glide list I followed the steps which are specified on the Advanced Custom Locking Scripts section. But I dont understand the use of using the watch list in this context. Can you please explain more on this how it would work on using the script..
Thanks
It’s mostly an example of something you can do if you needed to manipulate something else on a form based on a lock/unlock trigger. I don’t know that there’s any specific use case.
Is it possible to change the icon on the watch list and work notes list? Apparently the lock icon is confusing some of my users. They think it’s suppose to actually lock the field.
It’s probably possible but there’s no simple, direct way. I think the better approach may be to add some additional information to your form to explain usage if necessary.