I have custom fields underneath a relationship type that I want to restrict to view only or entirely remove if they are not a specific user. I can make the permissions work so the issue is load order I think. My jQuery code in Relationship.extra.tpl loads before the custom fields appear. I suppose my answer lies somewhere here https://docs.civicrm.org/dev/en/latest/framework/ajax/ but any pointers to get me in the right direction?
You can use preProcess or BuildForm hook on formname CustomDataType and unset the custom group or field based on user role or id
You can use PageRun hook and unset the variable in smarty template based on condition and it will not display on view page
since the custom fields are build using ajax, you can also use ajaxSuccess jq event to remove the custom field using Relationship.extra.tpl