been a long time since I've posted around here, bu...
# suitescript
m
been a long time since I've posted around here, but I was wondering if anyone has any examples of clean use of the n/query module. Everything i seem to write just feels ugly.
s
@mwalker To add to cleanliness a little bit, you actually dont need to create any of the join components when using the query module. It's a little better than having bomJoinComponent, etc.
Copy code
var queryMain = query.create({
            type: 'bomrevision'
        });
        var conditionOne = queryMain.createCondition({
            fieldId: 'billofmaterials.bomassemblylocation.ismasterdefaultbom',
            operator: <http://query.Operator.IS|query.Operator.IS>,
            values: true
        });
        var conditionTwo = queryMain.createCondition({
            formula: 'CASE WHEN NVL({effectivestartdate},CURRENT_DATE) <= CURRENT_DATE AND NVL({effectiveenddate},CURRENT_DATE) >= CURRENT_DATE THEN 1 ELSE 0 END',
            operator: query.Operator.EQUAL,
            values: 1,
            type: query.ReturnType.INTEGER
        });

        var itemFilter = [];
        for (var index in makePartArray) {
            var itemId = makePartArray[index].itemId;
            itemFilter.push(itemId);
            boms[itemId] = [];
        }
        var conditionThree = queryMain.createCondition({
            fieldId: 'billofmaterials.bomassemblylocation.assembly',
            operator: query.Operator.ANY_OF,
            values: itemFilter
        });

        queryMain.condition = queryMain.and(conditionOne, conditionTwo, conditionThree);
        var tempColumns = [
            {
                fieldId: 'billofmaterials.bomassemblylocation.assembly'
            },
            {
                fieldId: 'component.item'
            },
            {
                fieldId: 'component.bomquantity'
            },
            {
                fieldId: 'component.item^item.itemtype'
            }
        ]
        queryMain.columns = [];
        for (var i in tempColumns) {
            queryMain.columns.push(queryMain.createColumn(tempColumns[i]));
        }
m
yeah I see what you mean (removing the join), its actually really cool to use the multiple joined records in a component like that. I'll have to play with it, still not sure its clean though.