Convert a Query to SuiteQL and Run It

The following sample creates a query for customer records, converts it to its SuiteQL representation, and runs it.

/**
 * @NApiVersion 2.x
 */
require(['N/query'], function(query) {
    var myCustomerQuery = query.create({
        type: query.Type.CUSTOMER
    });


    myCustomerQuery.columns = [
        myCustomerQuery.createColumn({
            fieldId: 'entityid'
        }),
        myCustomerQuery.createColumn({
            fieldId: 'email'
        })
    ];


    myCustomerQuery.condition = myCustomerQuery.createCondition({
        fieldId: 'isperson',
        operator: query.Operator.IS,
        values: [true]
    });


    var mySQLCustomerQuery = myCustomerQuery.toSuiteQL();


    var results = mySQLCustomerQuery.run();
});

Leave a comment

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