Function to get data based on record type and field id using SuiteQL

  1. Input Parameters: The function expects a single parameter named record, which is an object containing two attributes: type and field.
  • type: Specifies the type of NetSuite record from which data needs to be retrieved (e.g., “customer”, “vendor”, “transaction”, etc.).
  • field: Specifies the field ID within the specified record type. This field will be used as a filter condition in the SuiteQL query.
  • value: Value to be compared (e.g., internal id)

getListQueryResult(record) {
                try {
                    let type = record.type;
                    let field = record.field;
                    let suiteQL = "";

                    if (!nsUtility.checkForParameter(type) || nsUtility.checkForParameter(field)) {
                        log.error("Error", "Missing Record Type");
                        return [];
                    }
                    
                        suiteQL = `
                            SELECT
                                id,
                                name
                            FROM
                                ${type}
                            WHERE
                                isinactive != 'T' AND
                                ${field} IN (${parseInt(record.value)})
                            ORDER BY
                                id`;

                    // Run the SuiteQL query
                    return query.runSuiteQL(suiteQL);
                } catch (e) {
                    log.error({ title: "Error @grw021_cm_data_model @getResults @getListQueryResult", details: e });
                    return [];
                }
            },

Leave a comment

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