How to Restrict related only for particular conditions

harinya
Tera Contributor

Hi 
Can some one please help on this
on the Issue form there is one related list Entities currently showing class, description columns client expecting more columns to be add but those columns should be visible only if entity table (on the entity form there one table called business process)for others remains the existing columns
how can this achieve

 

 

5 REPLIES 5

folusho
Tera Guru

@harinya 

 

You can achieve it by doing the following: 

 

1. Create Multiple Views:

-navigate to the List Layout for the related list table

-create different views (e.g., Default, Business_Process_View).

-Add the appropriate columns to each view.

folusho_0-1746763025068.png

 

Then 2. Use Client Script to Dynamically Switch Views:

function onLoad() {
    var entityType = g_form.getValue('entity_type'); // Replace with the actual field name

    if (entityType === 'business_process') {
        // Switch to the Business Process view
        setRelatedListView('Entity', 'Business_Process_View');
    } else {
        // Default view for other entities
        setRelatedListView('Entity', 'Default');
    }
}

// Helper Function to Change Related List View
function setRelatedListView(relatedListName, viewName) {
    var relatedList = GlideList2.get(relatedListName);
    if (relatedList) {
        relatedList.setView(viewName);
        relatedList.refresh();
    }
}

 

harinya
Tera Contributor

HI @folusho 
Thanks for Response but we don't have 2 views instead of creating new view can you please suggest is there any other way

 

@harinya 

Unfortunately, I don't know of any other way than to use List views.

Ankur Bawiskar
Tera Patron
Tera Patron

@harinya 

you can have multiple views and then switch the view in that related list based on form load

No other way.

See if the script shared by @folusho works for you and share the updates.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader