Create a Query for a Custom Field

The following sample creates a query for a custom field, custrecord_my_custom_field, and obtains the internal ID of the field.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /*
 * @NApiVersion 2.x
 */
require(['N/query'], function(query) {
    var customFieldIdQuery = query.create({
        type: query.Type.CUSTOM_FIELD
    });
    customFieldIdQuery.columns = [
        customFieldIdQuery.createColumn({
            fieldId: 'internalid'
        })
    ];
    customFieldIdQuery.condition = customFieldIdQuery.createCondition({
        fieldId: 'scriptid',
        operator: query.Operator.IS,
        values: 'custrecord_my_custom_field'
    });

    var results = customFieldIdQuery.run().asMappedResults();
    var customFieldInternalId = results[0].internalid;
    log.debug({
        title: 'Internal ID of the custom field is ',
        details: customFieldInternalId
    });
}); 

        

General Notices