Hide Name Value Pairs Buttons

TD8
Tera Contributor

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.

 

TD8_1-1715195330807.png

 

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

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) {}
}

Source - https://www.servicenow.com/community/developer-forum/how-to-make-name-value-pair-data-type-field-rea...

 

If you are hiding those buttons, how will the users create/remove a new pair?

 

Cheers

View solution in original post

3 REPLIES 3

James Chun
Kilo Patron

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) {}
}

Source - https://www.servicenow.com/community/developer-forum/how-to-make-name-value-pair-data-type-field-rea...

 

If you are hiding those buttons, how will the users create/remove a new pair?

 

Cheers

Community Alums
Not applicable

Hi @TD8 ,
Please find the below client script 

SanjayG_0-1715200552780.png

 

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

swathisarang98
Giga Sage
Giga Sage

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