Make child table Read-only based on parent state

VSN
Tera Expert

I have a requirement to make related list  tables  ready only based on associate parent  state. 

Per example if program is completed or approval states then I need all associate related list tables like projects, benefit plan, benefits plan breakdowns, cost plan, cost plan breakdown fields read only for employee manager role users.

 

Ui policy or Clint script is preferred way.

2 REPLIES 2

Deepak Shaerma
Kilo Sage

Hi @VSN 

Create a Onload Client Script on your table.
Modify the script as per your needs ,,, check table names also...

if (!g_user.hasRole('employee_manager')) {
        return;
    }

    // Read the state of the program
    var programState = g_form.getValue('state');

    // Define the states where the lists should be read-only
    var readOnlyStates = ['completed', 'approval'];

    // Function to make related list read-only
    function setRelatedListReadOnly(listName) {
        // Disable the new button
        g_form.setRelatedListControls(listName, false, false);
        
        // Disable the entire related list
        g_form.setRelatedListEditStatus(listName, false);
    }

    // If program state is in the read-only states list, make the related lists read-only
    if (readOnlyStates.includes(programState)) {
        setRelatedListReadOnly('projects');
        setRelatedListReadOnly('benefit_plan');
        setRelatedListReadOnly('benefit_plan_breakdowns');
        setRelatedListReadOnly('cost_plan');
        setRelatedListReadOnly('cost_plan_breakdown');
    }

Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma 


Vrushali  Kolte
Mega Sage

Hello @VSN ,

 

You can create ui policy or client script on child table that will check if the condition is matching and then make the fields read-only. You can add g_user.hasRole('employee_manager')  condition for role validation. Please refer the below post for more understanding -

 

https://www.servicenow.com/community/developer-forum/set-field-readonly-on-related-list-table/m-p/18...

 

If my answer solves your issue, please mark it as Accepted ✔️ and Helpful 👍 based on the impact.