Hi there,
Good question - this is a two-part solution, because "read-only" for a subgrid actually means two different things (inline editing vs. the New/Delete command buttons), and each has its own supported mechanism.
Step 1 - Detect the role reliably (handles multiple roles)
Use the supported client API Xrm.Utility.getGlobalContext().userSettings.roles. This returns a collection of lookup objects (GUID and display name) for every security role assigned to the user, including roles inherited through teams. Because it's the full set of the user's roles, the multi-role case (System Administrator + APEditor) is handled automatically - you just check whether "APEditor" exists in the collection.
A couple of notes worth knowing: the older userSettings.securityRoles property is deprecated, so use roles. Checking by role GUID rather than display name is more robust, since names can be renamed.
Step 2 - Disable inline editing on that subgrid
In a form OnLoad handler, get the grid control and disable it:
formContext.getControl("Subgrid_new_18").setDisabled(true);
setDisabled is a documented method on the GridControl and turns off inline editing for that specific control only - it doesn't affect the user's privileges anywhere else.
Step 3 - Hide the command-bar buttons (New, Add Existing, Delete)
setDisabled stops inline edits but doesn't remove the ribbon buttons, so handle those in the Command designer. For each command (New, Add Existing, Delete) on that subgrid, set Visibility to "Show on condition from formula" and supply a Power Fx condition so the button is hidden for APEditor users. This is the supported, declarative way to control command buttons and is more reliable than trying to hide them from JavaScript.
Doing Steps 2 and 3 together gives you a subgrid that is viewable but fully locked down (no inline edit, no create, no delete) for APEditor users, while leaving their permissions elsewhere untouched.
References:
Found this helpful? Please mark ✅ "Does this answer your question?" so others searching for the same issue can find it quickly. A 👍 on "Was this reply helpful?" or a ♥ Like is also much appreciated!
Raghav Mishra - LinkedIn | PowerAI Labs