Hide related list column using Client Script or Ui policy in ServiceNow

gowtham1610
Tera Contributor

Hi All,

I am trying to hide a column in a related list using client script under condition in ServiceNow

I tried using methods like : g_form.hideRelatedList(): - this is only used to hide whole related list but i want to hide only one column in related list 

just wanted to know is there any other client side methods  to hide columns in related list in ServiceNow

#ClientScript

#ServiceNow

5 REPLIES 5

Sneha KH
Tera Guru

Hello @gowtham1610 ,
Create a client script of type "OnLoad", select table name and insert the below script.

function onLoad() {
// 1. Set your condition here (e.g., check if user is NOT an admin)
if (!g_user.hasRole('admin')) {

// 2. Define the internal name of the related list table
var listTableName = 'u_your_related_table_name';

// 3. Define the internal name of the column/field to hide
var columnName = 'u_sensitive_field';

hideColumnInRelatedList(listTableName, columnName);
}
}

function hideColumnInRelatedList(listName, colName) {
try {
// Find the related list container using the list name
var listID = g_form.getTableName() + '.' + listName;
var listContainer = $j("div[id*='" + listID + "']");

if (listContainer.length > 0) {
// Hide the Header (TH)
listContainer.find('th[item_name="' + colName + '"]').hide();

// Hide all Data Cells (TD) in that column
listContainer.find('td[item_name="' + colName + '"]').hide();
}
} catch (e) {
console.log('Error hiding related list column: ' + e);
}
}

Tanushree Maiti
Tera Patron

Laveena-Agarwal
Mega Sage

Hi @gowtham1610 

Could you please share the condition under which you want to hide this column? Based on that, I can suggest the best-practice solution!

Ankur Bawiskar
Tera Patron

@gowtham1610 

but why you want to hide?

Not possible with script to hide any column in related list.

what's the business requirement?

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏