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!