Integrating Google App Script with Orbit Champion program: Submitting Form Data

This tutorial guides you on how to integrate Google App Script with Orbit, a tool for community building and developer advocacy. The focus is on submitting form data from a Google Form to Orbit using a custom script. The tutorial provides step-by-step instructions on defining form field mappings, submitting form data to Orbit, and setting up a Google Form trigger. By following this tutorial, you’ll be able to automate the process of sending data from your Google Form to your Orbit Champions program. This custom script will streamline your community-building efforts and enhance your developer advocacy.

広告ここから
広告ここまで

目次

    In this tutorial, we’ll explore how to integrate Google App Script with Orbit, a powerful tool for community building and developer advocacy.

    We’ll focus on submitting form data from a Google Form to Orbit using a custom script.

    By the end of this guide, you’ll have a functional script that automates the process of sending data from your Google Form to your Orbit Champions program(Beta).

    Prerequisites

    Before we get started, ensure you have the following:

    • An Orbit Champion program(beta): https://orbit.love/blog/what-is-a-champions-program
      • And it’s form submission id: https://app.orbit.love/submissions/{FORM_SUBMISSION_ID}
    • A Google Form created with fields corresponding to the data you want to send to Orbit Champion Program.

    Step 1: Define Form Field Mappings

    First, we need to establish a mapping between the form fields and their corresponding keys in Orbit.

    Modify the formFieldMappings array to match your Google Form’s fields and the desired keys in Orbit. The provided code is an example:

    
    const formFieldMappings = [{
      title: 'Your name',
      key: 'name'
    }, {
      title: 'Email',
      key: 'email'
    }, {
      title: 'GitHub username',
      key: 'github'
    }]

    Step 2: Submit Form Data to Orbit

    Next, we’ll create an asynchronous function, submitForm(e), that handles form submissions and sends the data to Orbit.

    This function will be triggered automatically when a user submits the Google Form.

    async function submitForm(e) {
        const formResponse = e.response.getGradableItemResponses();
        const items = {};
        for (const data of formResponse) {
          const value = data.getResponse();
          const title = data.getItem().getTitle();
          const matched = fieldMappings.find(mapping => mapping.title === title);
          if (!matched) continue;
          items[matched.key] = value;
        }
    
        const response = UrlFetchApp.fetch(`https://app.orbit.love/submissions/xxx-xxx-xxx-xxx`, {
          method: 'POST',
          contentType: 'application/x-www-form-urlencoded',
          payload: items
        })
        return JSON.parse(response.getContentText())
    }

    Step 3: Set Up Google Form Trigger

    To make our script execute upon form submissions, follow these steps:

    • From the Google Form editor, click on the three-dot menu and select “Script Editor.”
    • In the Apps Script editor, paste the entire submitForm function.
    • Save the script with a meaningful name.
    • Click on the clock icon (Triggers) in the toolbar to set up a new trigger.
    • Choose the event source as “From form” and the event type as “On form submit.”
    • Save the trigger.

    Conclusion:

    Congratulations!

    You’ve successfully created a custom Google App Script that connects your Google Form with your Orbit Champion program.

    Whenever a user submits the form, the data will be automatically sent to Orbit, streamlining your community-building efforts.

    広告ここから
    広告ここまで

    Random posts

    Home
    Search
    Bookmark