BMQL (BigMachines Query Language)

Overview

Oracle CPQ can query system tables and user-created Data Tables from within BML by using a SQL-like syntax.

This functionality has replaced the deprecated gettabledata() and getpartsdata() functions. For more information on these and other database functions, see the topic Direct DB Access.

BMQL is a function that contains the results of an SQL query. Click here for more information on SQL.

Highlights:

Beginning in Oracle CPQ 20A, BMQL functions are available to insert, delete, update, and modify Live Data Tables. When storing Transaction-related data within a Live Data Table is required as part of a business process, using BMQL functions to update Live Data Tables is recommended over using Web Services. Since the action is performed on a Live Data Table, there is no need to deploy the table after modification is complete. For more information, see Live Data Table Statement Keywords.

When running insert, delete, update, or modify from a BML debugger, the returned result recordset update is simulated. The changes to data tables occur only if the BMQL statement is executed through a user action.

Administration

ClosedBasics

Syntax: bmql(sqlQuery [, stringDict])

Parameters:

# Parameter Data Type Description
1 sqlQuery String The SQL query
2 [dict] String, Integer, or Float Optional: A dictionary populated with the language context variable as a key and an overriding language as the value.

Return Type: Record Set

This data type is a collection of dictionaries. It can also be used as a function in conjunction with BMQL.

Example of bmql():

rs = recordset();
if(...) {
rs = bmql(query1);
}
else {
rs = bmql(query2);
}
return rs;

ClosedAdvanced


ClosedOperators

User operators to refine your queries. There are two kinds of operators:

  • Relational Operators: =, <>, <, >, <=, >=, LIKE, NOT LIKE, IN, NOT IN, IS NULL, IS NOT NULL
  • Logical Operators: AND, OR
Operator Description Example
LIKE This is used as "contains". SELECT part_number FROM _parts WHERE part_number LIKE $var_1
NOT LIKE This is used as "does not contain". SELECT part_number FROM _parts WHERE part_number IS NOT LIKE $var_1
IN This is used to find a value within an array. SELECT part_number FROM _parts WHERE part_number LIKE $var_1 IN $lead_time
NOT IN
This is used to find values outside of an array. SELECT part_number FROM _parts WHERE part_number LIKE $var_1 NOT IN $lead_time
IS NULL This is used to find null values in an array. SELECT part_number FROM _parts WHERE part_number LIKE $var_1 IS NULL
IS NOT NULL This is used to find values that are not null in an array. SELECT part_number FROM _parts WHERE part_number LIKE $var_1 IS NOT NULL

ClosedWildcards


ClosedFinding Available Tables

Within each Function Wizard, scroll down to the end of the Behavior section to find a link that opens a pop-up window that will show all accessible databases and Data Tables. Select the database or Data Table name to see a list of column names and whether a column can be used in the WHERE clause.


BMQL does not support a parts query that retrieves more than 500 parts from a non-default Price Book.
  • The BMQL query is parsed at runtime.

  • OrderBy and Distinct cannot be grouped together using AND or OR.

  • For security reasons, the query cannot be built dynamically and passed into BMQL. Dynamic values can be passed in the WHERE clause of the query by preceding the variable name with a "$".


ClosedParameters


ClosedJOIN Clauses

JOIN clauses in BMQL support the ANSI standard SQL syntax for JOIN clauses. A JOIN clause combines rows from two or more tables, based on a related column between them. BMQL supports the following JOIN types:

  • INNER JOIN returns records that have matching values in the referenced tables.
  • LEFT OUTER JOIN returns all records from the left table, and matched records from the right table.
  • RIGHT OUTER JOIN returns all records from the right table, and matched records from the left table.

ClosedJoin Two Tables

ClosedJOIN Multiple Tables

ClosedDotted Notation


ClosedEnhanced ORDER BY Operation

Previously, BMQL only supported ORDER BY clauses in simple queries without dotted notation. Beginning in Release 18A, the ORDER BY clause to supports JOIN clauses, statements with dotted notation, and statements without dotted notation that reference unique columns in BMQL.

ClosedORDER BY Support for JOIN Clause

ClosedORDER BY with Dotted Notation

ClosedSort Multiple Columns


ClosedAlias Support for SELECT and FROM Clauses

Oracle CPQ 18A provides ANSI SQL JOIN support with aliasing in SELECT and FROM clauses. SQL aliases are used to give a table or a column a temporary name. Aliases are often used to make column names more readable. Aliases only exist for the duration of the query. For example: the following statement the column names for the returned results table will be renamed as "empLastName" instead of "T1.lastname", etc.

SELECT T1.lastName as empLastName, T1.firstName as empFirstName, T2.lastName as mgrLastName, T2.firstName as mgrfirstName, FROM Employee T1 INNER JOIN Employee T2 ON T1.mgrId = T2.employeeId

ClosedWHERE Clauses and Parameters


ClosedUsing Transaction Data in Configuration

You can access Commerce transaction data, from both main documents and sub-documents, in advanced functions within Configuration.

This functionality is not supported outside of Configuration.

Data Available using BMQL Transaction:

  • Date
  • Integer
  • Float
  • String
  • Currency
  • Summation
  • Boolean

The BMQL Transaction function is context-sensitive.

  • The function will automatically recognize the Transaction ID when the user arrives on the Configuration page through Commerce.
    • It is not possible to query a separate Transaction using this function.
  • Translations will be returned for menu values based on the current user’s language.
    • For other string type attribute values, the user-entered value will be returned; translations are not defined for such inputs.
  • For currency attributes, the exchange rate will be applied on the returned value if the current user’s session currency is not the same as the site's base currency.
When the user’s session currency is different from the site's base currency, exchange rates are applied to currency values being returned from advanced functions in Configuration.

The FullAccess user should take this into account when using BMQL Transaction in advanced functions, since BMQL also applies the exchange rate on the returned value.
Approval Comments, History, RTE, HTML, and File Attachment attributes are not available through BMQL Transaction.

Use Case Examples

For all of the use cases below, we'll be using a user-created Data Table named sammie.

Data Table example

ClosedSample Use Case 1: Using BMQL function

In this example, let's say you'd like to run a query to return the Price and Type from the sammie Data Table shown above.

  1. Using the information from the sammie Data Table, create a new script using BMQL that will return Price and Type. Click the checkboxes in the Select column to select your columns and the checkboxes in the From column to select your database object.
  2. Create a for...loop to loop through your record set created using the BMQL function.
  3. In this example, we are using the print statement to show the results of the query.

Use BMQL example

Now, you can compare the results of the query to what is on the table and see that it pulled the correct Type and Price from the table.

Use BMQL output example

In this example, we are using the same sample case, but adding the "distinct" keyword. Remember, using distinct will only return distinct values, essentially removing any duplicates.

BMQL 'distinct' example

As you can see, where there were multiple sets that were the same in the first example, now those have been removed.

BMQL 'distinct' output example


ClosedSample Use Case 2: Using the get function and the WHERE Clause

This example takes Sample Use Case 1 a step further by adding a WHERE clause to the select statement. We also add the get() function.

  1. Using the information from the sammie Data Table, create a new script using BMQL that will return Part, Description and Price when the Type in the Data Table is "Hot". Click the checkboxes in the Select column to select your columns and the checkboxes in the From column to select your database object.
  2. Create a for...loop to go through your record set created using the BMQL function.
  3. Use the get() function with record being used like a dictionary and Price being the data to be returned.

    BMQL 'get' example

As you can see below, "record" acts like a dictionary and returns the columns and data you requested. You should also notice the get() function at work, returning the price for each of the records.

BMQL 'get' output example


ClosedSample Use Case 3: Using a WHERE condition

In this example, we are going to add a condition. So, the first screen show we'll say that if the condition is true, that the predicate will query for the part number "HS001". When adding a WHERE condition, the syntax is $eval AND field = value. In this case, we are searching for part number "HS001" when the condition is True.

WHERE example WHERE output example

In the console, you'll notice that when the part number is "HS001", the Price and Type have been returned. We'll then evaluate what happens if the condition is False:

False condition example False condition output example

In the console, you'll notice that when the condition is False, the predicate (Part = 'HS001') is ignored and all other results are returned.


ClosedSample Use Case 4: Errors

The user can retrieve errors or warnings using the getMessage function.

getMessage example


ClosedSample Use Case 5: Recommended Item Rule

Recommended Item Rule example


ClosedSample Use Case 6: Using BMQL Transaction

In this example, we'll show you how to return commerce transaction data back to configuration. The attribute Opportunity Name has been set with the value Toni's Pizza.

Use BMQL Transaction example

This was set through a recommendation rule using BMQL Transaction. Notice the use of commerce.quote_process after the FROM statement. This is the variable name of the quote document from where you're querying data. You can also use the variable name of the sub-document (for example, line_process).

 commerce.quote_process FROM statement example

The WHERE clause is not accepted when you are returning commerce data to configuration.


Notes

  • BMQL is case-sensitive. Be aware of this when selecting your columns, fields, and database objects.
  • Capitalize your keywords to ensure that your query string easy to read.
  • For debugging BMQL, the context parameter field should be populated with "bsId=xxxxx" where xxxx is a valid BSID in Commerce.

On reconfigure, BMQL Transaction will return all line items.
  • The WHERE clause is not supported for a BMQL transaction.
  • The JOIN clauses are only supported for customer-defined tables. For example, if you have a query using a JOIN clause for the sytem-defined _parts table, you will receive an error message.

  • If the user does not arrive through Commerce, the BMQL transaction will return NULL. This also occurs when a model is configured using SOAP.
  • NULL and blank Integer values are treated as separate values:
    • NULL= 0
    • Blank = ""
  • Using NULL as an attribute value is strongly discouraged.
  • If you use logic that tests for NULL values in rule conditions or BML, confirm that the logic takes this difference into account.

Related Topics

Related Topics Link IconSee Also