Ready to get started?

Learn more about the CData Excel Add-In for Sage 300 or download a free trial:

Download Now

Excel Spreadsheet Automation with the QUERY Formula

Pull data, automate spreadsheets, and more with the QUERY formula.

The CData Excel Add-In for Sage 300 provides formulas that can edit, save, and delete Sage 300 data.The following three steps show how you can automate the following task: Search Sage 300 data for a user-specified value and then organize the results into an Excel spreadsheet.

The syntax of the CDATAQUERY formula is the following: =CDATAQUERY(Query, [Connection], [Parameters], [ResultLocation]);

This formula requires three inputs:

  • Query: The declaration of the Sage 300 data records you want to retrieve, written in standard SQL.
  • Connection: Either the connection name, such as Sage300Connection1, or a connection string. The connection string consists of the required properties for connecting to Sage 300 data, separated by semicolons.

    Sage 300 requires some initial setup in order to communicate over the Sage 300 Web API.

    • Set up the security groups for the Sage 300 user. Give the Sage 300 user access to the option under Security Groups (per each module required).
    • Edit both web.config files in the /Online/Web and /Online/WebApi folders; change the key AllowWebApiAccessForAdmin to true. Restart the webAPI app-pool for the settings to take.
    • Once the user access is configured, click https://server/Sage300WebApi/ to ensure access to the web API.

    Authenticate to Sage 300 using Basic authentication.

    Connect Using Basic Authentication

    You must provide values for the following properties to successfully authenticate to Sage 300. Note that the provider reuses the session opened by Sage 300 using cookies. This means that your credentials are used only on the first request to open the session. After that, cookies returned from Sage 300 are used for authentication.

    • Url: Set this to the url of the server hosting Sage 300. Construct a URL for the Sage 300 Web API as follows: {protocol}://{host-application-path}/v{version}/{tenant}/ For example, http://localhost/Sage300WebApi/v1.0/-/.
    • User: Set this to the username of your account.
    • Password: Set this to the password of your account.
  • ResultLocation: The cell that the output of results should start from.

Pass Spreadsheet Cells as Inputs to the Query

The procedure below results in a spreadsheet that organizes all the formula inputs in the first column.

  1. Define cells for the formula inputs. In addition to the connection inputs, add another input to define a criterion for a filter to be used to search Sage 300 data, such as AllowPartialShipments.
  2. In another cell, write the formula, referencing the cell values from the user input cells defined above. Single quotes are used to enclose values such as addresses that may contain spaces.
  3. =CDATAQUERY("SELECT * FROM OEInvoices WHERE AllowPartialShipments = '"&B5&"'","User="&B1&";Password="&B2&";URL="&B3&";Company="&B4&";Provider=Sage300",B6)
  4. Change the filter to change the data.