The below script can be used to return the Manager of Any Resource from any CRM object, you only need that Resource PartyId.

For example in Opportunity if you want to get the Opportunity Owner Manager, you only need to get the Owner Id, which is actually a ootb attribute found in the groovy palette.

In Partners for example that owner Id is hold by the Attribute Account Director.

def ResourcePartyId =   VALUE OF THE RESOURCE PARTY ID
  
def view_Resource = newView(‘Resource’)  
def view_Criteria = newViewCriteria(view_Resource)  
def view_criteria_row = view_Criteria.createRow()  
def view_condition = view_criteria_row.ensureCriteriaItem(‘PartyId’)  
view_condition.setOperator(‘=’)  
view_condition.setValue(ResourcePartyId)  
view_Criteria.insertRow(view_criteria_row)  
view_Resource.appendViewCriteria(view_Criteria)  
view_Resource.setMaxFetchSize(1)  
view_Resource.executeQuery()  
  
def ManagerNameID = view_Resource.first()?.ManagerPartyId  
  
  
view_condition.setValue(ManagerNameID)  
view_Criteria.insertRow(view_criteria_row)  
view_Resource.appendViewCriteria(view_Criteria)  
view_Resource.setMaxFetchSize(1)  
view_Resource.executeQuery()  
  
def ManagerUserName = view_Resource.first()?.Username
 
The variable ManagerUserName  will hold the Manager User Name

Leave a Reply

Your email address will not be published. Required fields are marked *