Skip to content
Groovy 29 – Generic Script To Return the Manager of a Resource

Return Manager of Any Resource

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

For example, in Opportunity, if you want to get the Opportunity Owner's Manager, you only need to get the Owner Id, which is an OOTB attribute found in the Groovy palette.

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

Groovy Code

        // Groovy Code Snippet
        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's User Name.