give priority to PartyLegalEntity/CompanyID over EndpointID, closes #4681