- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 12:11 PM
Anyone know an easy way to hide the buttons next to a name/value pair field? I understand why they are there but have a specific requirement to remove them.
Highlighted below.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 01:27 PM
Hi @TD8,
I am not sure if there is a better way to do this but you may need to do some DOM manipulation
e.g. onLoad Client Script (make sure Isolate script checkbox is unchecked)
function onLoad() {
setTimeout(readOnlyNameValue, 1000);
}
function readOnlyNameValue() {
try {
// Make the field read only
var fieldName = 'u_my_dictionary'; //replace with your field name
var el = $('element.' + g_form.tableName + '.' + fieldName);
// Disable buttons
el.select('button').each(function(elmt) {
elmt.hide();
});
} catch (e) {}
}
If you are hiding those buttons, how will the users create/remove a new pair?
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 01:27 PM
Hi @TD8,
I am not sure if there is a better way to do this but you may need to do some DOM manipulation
e.g. onLoad Client Script (make sure Isolate script checkbox is unchecked)
function onLoad() {
setTimeout(readOnlyNameValue, 1000);
}
function readOnlyNameValue() {
try {
// Make the field read only
var fieldName = 'u_my_dictionary'; //replace with your field name
var el = $('element.' + g_form.tableName + '.' + fieldName);
// Disable buttons
el.select('button').each(function(elmt) {
elmt.hide();
});
} catch (e) {}
}
If you are hiding those buttons, how will the users create/remove a new pair?
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 01:37 PM - edited 05-08-2024 02:20 PM
Hi @TD8 ,
Please find the below client script
function onLoad() {
// This script assumes you are targeting all name-value pair buttons; refine the selector as needed
var buttons = document.querySelectorAll('.name-value-pair button');
buttons.forEach(function(button) {
button.style.display = 'none';
});
}
The only concern is how would the users add or remove the pairs.
Note: This is not ServiceNow best practice to manipulate the DOM.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 01:38 PM
Hi @TD8 ,
As it is out of the box field type its not possible to do and Dom manipulation is not suggested as it is not Servicenow Best Practice.
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang