Hide related list column using Client Script or Ui policy in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @gowtham1610
It is not possible to dynamically hide a specific column within a related list using standard client-side methods.
OOB its not supported feature.
You can refer this links on same requirement:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
