fbpx

Export Data to PDF – Power App – Custom Connector

Use Case: Export Course Management Data

We will create a Custom Connector to export data from the following Dataverse tables (Refer Dataverse Datamodel):

  • Courses: Stores course information (e.g., Course Name, Description, Start Date).
  • Students: Stores student details (e.g., Name, Email, Enrollment Status).
  • Instructors: Stores instructor details (e.g., Name, Email, Assigned Courses).

The connector will support:

  1. Retrieving all courses.
  2. Retrieving students enrolled in a course.
  3. Retrieving instructors assigned to a course.

Step-by-Step Implementation

1. Set Up Your Dataverse Tables

Ensure your Dataverse data model includes:

  • Courses:
    • Fields: CourseName, Description, StartDate, CourseID (unique identifier).
  • Students:
    • Fields: StudentName, Email, EnrollmentStatus, CourseID (lookup to Courses).
  • Instructors:
    • Fields: InstructorName, Email, CourseID (lookup to Courses).

Populate sample data to test the connector functionality.


2. Expose Dataverse Data as an API

  1. Enable Dataverse Web API:
    • Dataverse data is accessible via the Dataverse Web API.
    • Use OData queries to filter and retrieve specific data.
  2. Example API Endpoints:
    • Get all courses:plaintextCopy codeGET https://<environment>.api.crm.dynamics.com/api/data/v9.2/courses
    • Get students by course:plaintextCopy codeGET https://<environment>.api.crm.dynamics.com/api/data/v9.2/students?$filter=CourseID eq <CourseID>
    • Get instructors by course:plaintextCopy codeGET https://<environment>.api.crm.dynamics.com/api/data/v9.2/instructors?$filter=CourseID eq <CourseID>
  3. Authentication:
    • Use OAuth 2.0 with Azure Active Directory to authenticate API calls.

3. Create the Custom Connector

  1. Access Power Platform:
  2. Start a New Connector:
    • Click + New Custom Connector > Create from Blank.
    • Name the connector (e.g., CourseManagementExport).
  3. Set Up General Information:
    • Host: Add your Dataverse environment URL (e.g., https://<environment>.api.crm.dynamics.com).
    • Base URL: Use /api/data/v9.2.
  4. Configure Security:
    • Go to the Security tab and select OAuth 2.0.
    • Provide the following:
      • Client ID and Client Secret from your Azure AD App Registration.
      • Token URL: https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token.
      • Scope: https://<environment>.api.crm.dynamics.com/.default.

4. Define Actions in the Connector

  1. Add Action: Get Courses
    • Go to the Definition tab.
    • Click + New Action and configure:
      • Summary: Fetch all courses.
      • Operation ID: GetCourses.
      • Request:
        • Method: GET.
        • URL: /courses.
      • Response:
        • Add a sample response:jsonCopy code[ { "CourseID": "1", "CourseName": "Math 101", "Description": "Basic Mathematics", "StartDate": "2024-01-15" } ]
  2. Add Action: Get Students for a Course
    • Configure another action:
      • Summary: Fetch students for a specific course.
      • Operation ID: GetStudentsByCourse.
      • Request:
        • Method: GET.
        • URL: /students?$filter=CourseID eq {CourseID}.
        • Add a parameter for CourseID.
      • Response:
        • Add a sample response:jsonCopy code[ { "StudentName": "John Doe", "Email": "john.doe@example.com", "EnrollmentStatus": "Active" } ]
  3. Add Action: Get Instructors for a Course
    • Configure another action:
      • Summary: Fetch instructors for a specific course.
      • Operation ID: GetInstructorsByCourse.
      • Request:
        • Method: GET.
        • URL: /instructors?$filter=CourseID eq {CourseID}.
        • Add a parameter for CourseID.
      • Response:
        • Add a sample response:jsonCopy code[ { "InstructorName": "Jane Smith", "Email": "jane.smith@example.com" } ]

5. Test the Custom Connector

  1. Go to the Test tab in the Custom Connector.
  2. Enter sample parameters (e.g., CourseID).
  3. Verify the response:
    • Check that the data is retrieved correctly from Dataverse.

6. Integrate the Connector

  1. In Power Automate:
    • Use the connector to export data automatically.
    • Example: Export student and instructor data to a SharePoint list or email as a CSV.
  2. In Power Apps:
    • Use the connector as a data source to display or manipulate course data in Canvas or Model-Driven Apps.

Leave a Reply

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