---
sourceDocument: Brazil Sales Customer Relationship Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/order-management

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil Sales Customer Relationship Management

ft:clusterId :

    - omgmt

bundleId :

    - omgmt

workflow :

    - Customer and Industry


---

# ServiceNow Quote Experience use case: Document generation with Google Docs

# ServiceNow Quote Experience use case: Document generation with Google Docs {#ariaid-title1}

Release version: Brazil  
Updated March 12, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 6 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of ServiceNow Quote Experience use case: Document generation with Google Docs

This guide explains how ServiceNow customers can generate documents from ServiceNow Quote Experience by integrating Google Docs with Google Apps Script.
By using custom Google Apps Script APIs, customers can directly receive GET and POST requests without middleware, streamlining document creation triggered from ServiceNow CPQ or Quote Experience.
Show full answer Show less  

## Key Features

* **Integration Methods:** Document generation can be initiated either via ServiceNow CPQ webhooks sending POST requests or directly through ServiceNow Quote Experience automation.
* **Google Apps Script Development:** Within a Google Doc, developers write JavaScript in the Apps Script editor (accessed via Extensions \> Apps Script) to handle GET (doGet) and POST (doPost) requests.
* **doGet Function:** Used primarily to verify that the web app is running by returning a simple text response when accessed via URL.
* **doPost Function:** Handles incoming POST requests containing JSON data, triggers document creation based on a Google Doc template, and returns the URL of the generated document.
* **Transform Template:** JSON data from ServiceNow CPQ or Quote Experience is transformed into a structured format containing transaction and line item details for document population.
* **Document Generation Logic:** A custom function (e.g., createGoogleDocFromTemplate) copies a Google Doc template, replaces placeholders with actual data values, saves the document, optionally sets sharing permissions to public view, and returns the document URL.
* **Logging and Debugging:** Use Logger.log() within Apps Script for basic debugging; for advanced logging, connect to Google Cloud Platform Logs Explorer filtered by appscriptfunction resource type.
* **Deployment:** Deploy the script as a web app with execution set to the developer's account and access set to "Anyone." Deployment provides live and dev URLs for production and testing purposes.
* **Version Management:** Supports creating new versions for deployments, editing existing deployments to point to new versions, and rolling back to previous versions if needed, ensuring safe updates and testing cycles.

## Key Outcomes

* Customers can automate document generation from ServiceNow Quote Experience data using Google Docs templates, improving efficiency and reducing manual effort.
* Direct integration without middleware simplifies architecture, reducing points of failure and maintenance overhead.
* Flexible customization via Apps Script allows tailored document content based on transaction and line data.
* Version control and deployment management ensure reliable updates and quick rollback capability.
* Accessible logging through Google Cloud facilitates troubleshooting and monitoring of document generation workflows.  
Generate documents from ServiceNow Quote Experience by using Google Docs and Google Apps Script.

To generate a document from ServiceNow Quote Experience, Google Docs combined with Google Apps Script provides an efficient and straightforward solution. By creating custom APIs using Apps Script, you can easily receive GET and POST requests from a direct
URL. This eliminates the need for middleware, streamlining integration with services like ServiceNow CPQ or ServiceNow Quote Experience.  
You can trigger document generation by either of these methods:

* ServiceNow CPQ Webhook: Automatically send POST requests to initiate document creation.
* ServiceNow Quote Experience: Use this for managing and automating processes.
{#transaction-manager-use-case-document-generation-with-google-docs__ul_hjj_lvn_3hc}

## Setting up a Google doc to pull ServiceNow CPQ data {#transaction-manager-use-case-document-generation-with-google-docs__Setting-up-a-Google-Doc-to-pull-Logik-data}

To access the developer window, open the Google doc where you want to integrate the script. In the menu bar, go to Extensions \> Apps Script to open the development environment.

You can write custom JavaScript to process data and interact with Google Docs by using the Apps Script editor.

## Coding {#transaction-manager-use-case-document-generation-with-google-docs__Coding}

Google Apps Script includes GET and POST requests.

* GET requests (`doGet`) respond with a simple text output, useful for verifying that the web app is running.
* POST requests (`doPost`) handle incoming data (usually JSON), generates the document based on the template, and returns a link to the newly created document.

{#transaction-manager-use-case-document-generation-with-google-docs__ul_ttg_2pn_3hc}

This [video](https://www.youtube.com/watch?v=N3vnUgjQCGU) explains how the `doGet` and `doPost` work in a Google Doc app script.

When using ServiceNow Quote Experience, you need to transform the JSON to send over to Google Docs. Below is an example template. If you are using a webhook, see [Webhooks](https://servicenow-prod.fluidtopics.net/YTNk5Ft3qMZ81qdr7RgFMQ "Webhooks are endpoints that can receive a POST request whenever a configuration is saved.") for how the data will be sent over to Google Docs.

The following code block shows an example Transform Template, sent as a POST to the doPost function.

    { 
      "transaction": { 
        "uuid": "{{txn.uuid}}", 
        "term": {{txn.term}}, 
        "stage": "{{txn.stage}}", 
        "status": "{{txn.status}}", 
        "account": "{{txn.account}}", 
        "endDate": "{{txn.endDate}}", 
        "netTotal": {{txn.netTotal}}, 
        "termUnit": "{{txn.termUnit}}", 
        "createdBy": "{{txn.createdBy}}", 
        "quoteName": "{{txn.quoteName}}", 
        "startDate": "{{txn.startDate}}", 
        "accountName": "{{txn.accountName}}", 
        "createdDate": "{{txn.createdDate}}", 
        "opportunity": "{{txn.opportunity}}", 
        "paymentTerm": "{{txn.paymentTerm}}", 
        "quoteNumber": "{{txn.quoteNumber}}", 
        "contractTerm": {{txn.contractTerm}}, 
        "contractType": "{{txn.contractType}}", 
        "currencyCode": "{{txn.currencyCode}}", 
        "estTaxAmount": {{txn.estTaxAmount}}, 
        "modifiedDate": "{{txn.modifiedDate}}", 
        "billToAddress": "{{txn.billToAddress}}", 
        "hardwareTotal": {{txn.hardwareTotal}}, 
        "servicesTotal": {{txn.servicesTotal}}, 
        "shipToAddress": "{{txn.shipToAddress}}", 
        "softwareTotal": {{txn.softwareTotal}}, 
        "discountAmount": {{txn.discountAmount}}, 
        "expirationDate": "{{txn.expirationDate}}", 
        "lastModifiedBy": "{{txn.lastModifiedBy}}", 
        "primaryContact": "{{txn.primaryContact}}", 
        "customerSegment": "{{txn.customerSegment}}", 
        "discountPercent": {{txn.discountPercent}}, 
        "transactionType": "{{txn.transactionType}}", 
        "estTaxPercentage": {{txn.estTaxPercentage}}, 
        "agreementDiscount": {{txn.agreementDiscount}}, 
        "taxEntityLocation": "{{txn.taxEntityLocation}}", 
        "transactionNumber": {{txn.transactionNumber}}, 
        "totalPriceEstimate": {{txn.totalPriceEstimate}}, 
        "overallDealDiscount": {{txn.overallDealDiscount}}, 
        "annualTransactionBands": "{{txn.annualTransactionBands}}", 
        "annualTransactionCount": {{txn.annualTransactionCount}}, 
        "accountSpecificDiscount": {{txn.accountSpecificDiscount}} 
      },   
      "lines": [
      {{#each lines}} 
        { 
          "uuid": "{{txn.line.uuid}}", 
          "productInfo": {
            "productId": "{{txn.line.productId}}",
            "productSku": "{{txn.line.productSku}}",
            "productCode": "{{txn.line.productCode}}",
            "productName": "{{txn.line.productName}}",
            "productType": "{{txn.line.productType}}",
            "productDescription": "{{txn.line.productDescription}}"
          },
          "pricing": {
            "netPrice": {{txn.line.netPrice}},
            "listPrice": {{txn.line.listPrice}},
            "discountAmount": {{txn.line.discountAmount}},
            "discountPercent": {{txn.line.discountPercent}},
            "netTotal": {{txn.line.netTotal}},
            "customerLineDiscount": {{txn.line.customerLineDiscount}},
            "agreementLineDiscount": {{txn.line.agreementLineDiscount}}
          },
          "dates": {
            "startDate": "{{txn.line.startDate}}",
            "endDate": "{{txn.line.endDate}}",
            "createdDate": "{{txn.line.createdDate}}",
            "modifiedDate": "{{txn.line.modifiedDate}}"
          },
          "quantity": {{txn.line.quantity}},
          "currencyCode": "{{txn.line.currencyCode}}",
          "configUUID": "{{txn.line.configUUID}}",
          "orderDetails": {
            "globalOrder": {{txn.line.globalOrder}},
            "orderNumber": {{txn.line.orderNumber}},
            "transactionLineNumber": {{txn.line.transactionLineNumber}}
          },
          "termDetails": {
            "term": {{txn.line.term}},
            "termUnit": "{{txn.line.termUnit}}",
            "termMultiplier": {{txn.line.termMultiplier}}
          },
          "approvals": "{{txn.line.approvals3}}",
          "lastModifiedBy": "{{txn.line.lastModifiedBy}}"
        }
        {{#unless @last}},{{/unless}} 
      {{/each}}
      ]
    }

If you do not set the `doGet` function and try to access the URL you will receive an error. If not using the `doGet` for other purposes, it is best to always set it to the following
and just modify the text.

    function doGet(e) {
      return ContentService.createTextOutput('Document Generation Web App is running.');
    }

When you access the live URL, you receive this message:

The `doPost` is important, because it will probably handle the Webhook or Integration payloads being sent from ServiceNow CPQ via POST requests.

Next, we create a function to generate a Google Doc using the `doPost` function.

In your Google Apps script, the `doPost` function will receive a
POST request containing data (in JSON format) that you want to populate into a Google Doc template. The main logic for interacting with the Google Doc (i.e., replacing placeholders like `{{EXAMPLE}}` with actual
values) will be placed in a separate function that is called from `doPost`.

To set up the `doPost` function, define the `doPost` function to handle incoming POST requests and call
your custom document generation function. Below is an example of how to structure it.

    function doPost(e) {
      // Parse the JSON data from the POST request
      const postData = JSON.parse(e.postData.contents);

      // Call the function to create and populate the Google Doc
      const docLink = createGoogleDocFromTemplate(postData);

      // Return the public link to the generated document in the response
      return ContentService.createTextOutput(docLink);
    }

In this code:

* The `postData` object contains the parsed data sent in the POST request.
* `createGoogleDocFromTemplate(postData)` is the function you will define to handle the Google Docs generation.
* The `docLink` is the public link to the generated Google Doc, returned to the caller.

{#transaction-manager-use-case-document-generation-with-google-docs__ul_vtg_2pn_3hc}

Next, create the document generation function. The `createGoogleDocFromTemplate` function will:

1. make a copy of a Google Doc template.
2. replace placeholders (e.g., `{{EXAMPLE}}`) in the document with the corresponding data.
3. return a public link to the generated document.

{#transaction-manager-use-case-document-generation-with-google-docs__ol_wtg_2pn_3hc}The following code block shows an example `createGoogleDocFromTemplate` function:

    function createGoogleDocFromTemplate(data) {
      // Specify the ID of the Google Doc template
      var templateId = 'YOUR_TEMPLATE_DOC_ID_HERE';
      // Make a copy of the template
      var templateDoc = DriveApp.getFileById(templateId).makeCopy();
      var doc = DocumentApp.openById(templateDoc.getId());
      var body = doc.getBody();
      // Replace placeholders with actual data from the POST request
      body.replaceText('{{ACCOUNT_NAME}}', data.transaction.accountName);
      body.replaceText('{{QUOTE_NUMBER}}', data.transaction.quoteNumber);
      body.replaceText('{{USER}}', data.transaction.createdBy);
      // Continue to replace all other placeholders...
      // Save and close the document
      doc.saveAndClose();
      // Make the document public (optional, based on your needs)
      templateDoc.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
      // Return the public link to the newly created document
      return templateDoc.getUrl();
    }

In this function:

* The templateId variable stores the Google Doc template's ID. You should replace `'YOUR_TEMPLATE_DOC_ID_HERE'` with the actual ID of your template.
* `makeCopy()` creates a copy of the template.
* `replaceText('{{EXAMPLE}}', data.key)` replaces each placeholder in the document with actual data from the incoming POST request. For example, `{{ACCOUNT_NAME}}` is replaced by `data.transaction.accountName`.
* The document is made public with `setSharing()`, but you can adjust the sharing settings as needed.
{#transaction-manager-use-case-document-generation-with-google-docs__ul_xtg_2pn_3hc}

## Logging {#transaction-manager-use-case-document-generation-with-google-docs__Logging}

Google Apps Script offers built-in logging via Logger.log() for debugging, but better logging is available in Google Cloud Logs. To access logs:

Go to \> ViewExecutions to check outputs from your script. Then, connect your project to the Google Cloud Platform to view the logs.

In the Google Cloud Logs Explorer, apply the filter `resource.type="app_script_function"` to view logs related to your app.

## Deploying {#transaction-manager-use-case-document-generation-with-google-docs__Deploying}

* Click the "Deploy" button in the top right corner of the Apps Script editor.
* Select "Deploy as web app."
* Set the project version (you can create a new one).
* Define who can access the app:
  * Execute as: This should be set to Me, so the script runs with your permissions.
  * Who has access: Choose "Anyone" (public).

  {#transaction-manager-use-case-document-generation-with-google-docs__ul_b5g_2pn_3hc}

{#transaction-manager-use-case-document-generation-with-google-docs__ul_a5g_2pn_3hc}

Once deployed, you'll get a URL ending in `/exec` for live usage and `/dev` for testing. This is the URL that users will target to trigger the `doGet` function or send POST requests to
trigger `doPost`.

In the following examples, the ellipsis (...) represents the unique App Script number for your script.

* Live: `https://script.google.com/macros/s/.../exec`
* Dev: `https://script.google.com/macros/s/.../dev`

{#transaction-manager-use-case-document-generation-with-google-docs__ul_e5g_2pn_3hc}

If you want to test your changes before pushing them live, use the Dev URL to test your script with real data.

Every time you redeploy, you need to create a new version of your script. Follow these steps:

1. In the Google Apps Script editor, click the Deploy button in the top right.
2. Select Manage deployments from the menu.
3. In the Deployments window, click Edit on the existing deployment, or create a new deployment.
4. Click Select Version, and then click New version.

{#transaction-manager-use-case-document-generation-with-google-docs__ol_g5g_2pn_3hc}

In the pop-up window, you can give your version a name or description. This is optional, but helpful for tracking changes. Click Save to create the new version.

To view or manage your current deployments:

1. In the Google Apps Script editor, click the Deploy.
2. Select Manage deployments. Here you'll see all active versions of your script.
3. You can edit, delete, or redeploy any version by clicking the three-dot menu next to the version.

{#transaction-manager-use-case-document-generation-with-google-docs__ol_i5g_2pn_3hc}

* Edit: Update an existing deployment to point to a new version.
* Delete: Remove the deployment entirely (Note: the live link will stop working if the deployment is deleted).

{#transaction-manager-use-case-document-generation-with-google-docs__ul_j5g_2pn_3hc}

If needed, you can roll back to an older version of your web app:

1. Go to Deploy \> Manage deployments.
2. Find the previous version you want to return to and click Edit.
3. Select the earlier version from the Select Version menu.
4. Click <kbd class="ph userinput">Deploy</kbd> to activate the previous version.

{#transaction-manager-use-case-document-generation-with-google-docs__ol_k5g_2pn_3hc}

This provides an easy way to revert any issues that may arise with newer versions.

*[\>]: and then


