Answers.Body: <p>Putting this in Relationship.extra.tpl works. Both ajaxSuccess or ajaxComplete events works. Thank you Pradeep.                                                             </p>
  
  <pre><code>{literal}
  &lt;script&gt;
  CRM.$( function( $ ) {
      $( document ).ajaxSuccess(function( event, request, settings ) {
       // do stuff
      } )
   } )
  &lt;/script&gt;
  {/literal}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-24T14:52:49.087Z
Answers.LastActivityDate: 2020-03-24T14:52:49.087Z
Answers.UserDisplayName: Andy Burns
Answers.Body: <p>You can use preProcess or BuildForm hook on formname CustomDataType and unset the custom group or field based on user role or id</p>
  
  <p>You can use PageRun hook and unset the variable in smarty template based on condition and it will not display on view page</p>
  
  <p>since the custom fields are build using ajax, you can also use ajaxSuccess jq event to remove the custom field using Relationship.extra.tpl</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-24T00:40:06.873Z
Answers.Text: Can this be done in an extra.tpl file?
Answers.UserDisplayName: Andy Burns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-24T01:47:43.517Z
Answers.Text: Try customdatatype.tpl but this file is invoked on all entity
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-24T00:32:54.173Z
Answers.LastActivityDate: 2020-03-24T15:46:10.043Z
Answers.LastEditDate: 2020-03-24T15:46:10.043Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>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 <a href="https://docs.civicrm.org/dev/en/latest/framework/ajax/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/ajax/</a> but any pointers to get me in the right direction?</p>
  
Tags: <templates>
Title: Modifying Relationship.tpl modal
ThreadText: # Modifying Relationship.tpl modal
  
  (Asked by: username_0 on 2020-03-23)
  
  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?
  
  **Tags:** templates
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-03-24. Score: 1 | Accepted answer
  
  Putting this in Relationship.extra.tpl works. Both ajaxSuccess or ajaxComplete events works. Thank you username_1.
  
  ```
  {literal}
  <script>
  CRM.$( function( $ ) {
      $( document ).ajaxSuccess(function( event, request, settings ) {
       // do stuff
      } )
   } )
  </script>
  {/literal}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2020-03-24. Score: 2
  
  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
  
  > **Comments:**
  > **username_0**: Can this be done in an extra.tpl file?  
  > **username_1**: Try customdatatype.tpl but this file is invoked on all entity  
  
  ---
  
  