locked
oData Query to hide tabs on crm form 2013 RRS feed

  • Question

  • Hi,

    I am trying to hide tabs based on oData query results in another form.

    Basically, main form has 1:N relationship with an entity(another form) which has few lookup fields to select for the users.

    When user selects a value in from the lookup field and saves the form, upon main form load I need to test if the current logged in user and the user selected lookup field 'name' both are same. If so I will hide few tabs.

    This is the code below i've written but I don't see my desired results.

    Can someone please let me know any corrections needed.

    Thanks

    
    
    • Edited by ReignFan Tuesday, August 5, 2014 1:07 PM none
    • Changed type ReignFan Wednesday, August 6, 2014 6:57 PM
    • Changed type ReignFan Wednesday, August 6, 2014 6:57 PM
    Monday, July 21, 2014 6:25 PM

All replies

  • Hi,

    As per my understanding you have 2 entities say new_parent and new_medical. They have 1:N relationship.
    On new_parent form load you wanted to check if there exists any related new_medical record where new_exclusion name is equal to logged in user then hide the respective tab.

    I have attached the code as per above understaing. Please replace "new_parent/Id" with your parent lookup field on new_medical in query.

    function HideTabOnLoad()
    {
    var userName=Xrm.Page.context.getUserName();
    var memberLookup=RetrieveName();
    if(userName==memberLookup)
    {
    Xrm.Page.ui.tabs.get("Related_Medical").setVisible(false);
    }
    else
    {
    Xrm.Page.ui.tabs.get("Related_Medical").setVisible(true);
    }
    }
    function RetrieveName()
    {
    var ClientUrl=Xrm.Page.context.getClientUrl();
    var oData_EndPoint="/XRMServices/2011/OrganizationData.svc";
    var oData_EntityCollection="/new_medicalSet";
    var Query="?$select=new_Exclusion&$filter=new_Exclusion/Id ne null and new_Parent/Id eq guid('"+Xrm.Page.data.entity.getId()+"')";
    var URL=ClientUrl+oData_EndPoint+oData_EntityCollection+Query;

    //synchronous XMLHttpRequest to retrieve account record
    var req=new XMLHttpRequest();
    req.open("GET",encodeURI(URL),false);
    req.setReuestHeader("Accept","application/json");
    req.setRequestHeader("Content-Type","application/json;charset=utf-8");
    req.send(null);
    var records = JSON.parse(req.responseText).d;
    //Read the  name
    alert( records.results[0].new_Exclusion.Name);
    return records.results[0].new_Exclusion.Name;
     
    }

    HTH!

    • Marked as answer by ReignFan Tuesday, July 22, 2014 1:48 PM
    Tuesday, July 22, 2014 4:41 AM
  • Hi

    var records = JSON.parse(req.responseText).d;
      
      if(records!=null && records.results.length>=1)
      {
      for(var i=0;i<records.results.length;i++)
      {
      var securityEntity=records.results[i];
      alert(securityEntity.new_Exclusion.Name);
      }
      }

    HTH!

    Monday, July 28, 2014 5:21 AM