Create a Custom Formula Field

A formula field is required to identify whether a Microsoft Teams already exists for the record. To create a formula field, follow these steps:

  1. Navigate to Configuration > Sandboxes to create and enter a sandbox with Application Composer.
  2. From the sandbox, open Application Composer from the Tools menu.
  3. In Application Composer, expand the Standard Objects node, and then expand Opportunity.

    Note: You can also use these steps to create a team and access Microsoft Teams for other objects such as custom objects as well.
  4. Click Fields as shown in this example screenshot.

    Screenshot showing where to access Formula field type

  5. Click the Custom Fields tab.
  6. On the Custom Fields tab, click New.
  7. Select Formula as the field type with the following details.
    1. Formula Type: Text
    2. Display Label: microsoftTeamCreated
  8. Click Next.
  9. Copy and paste the following groovy code:
    def conn = adf.webServices.collaborations;
    try
    {
      // Provide query parameter for the account object you want to receive 
      def queryParams = ['finder':'GetCollaborationsForObjectFinder;ObjectId='+OptyId+',Validate=true']
      conn.dynamicQueryParams = queryParams
      def collabResponse = conn.GET()
      if (collabResponse.count == 0 ) {
         return "NO"; 
      }
      if (collabResponse.count > 0 ) {
        return "YES"; 
      }
      return "ERROR";
    }
    catch(Exception ex)
    {
      println(conn.statusCode+""); 
      println(conn.httpErrorResponse+""); 
      return "ERROR";
    }
    Note: To set up the integration for custom objects you can copy the scripts provided but you must replace the OptyId value with the ID field for the custom object in all the sample scripts.
  10. Click Submit.