I have an Order where I am checking the line to se...
# suitescript
m
I have an Order where I am checking the line to see if a field is checked, and if it is, I add an additional line. However, each time I edit the order, the additoinal line keeps getting added. It seems my condition item_id != '24464' is being ignored. What I'm I doing wrong?
Copy code
for (var i = 0; i < item_count; i++) {
    const item_id = current_record.getSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        line: i
    })
    log.debug({title: "Current Line No:", details: i});
    log.debug({title: "Item", details: item_id});

    const add_tax = current_record.getSublistValue({
        sublistId: 'item',
        fieldId: 'custcol_add_tax',
        line: i
    })

    if (add_tax == true && item_id != '24464') {
        log.debug({title: "Requires Tax", details: add_tax});
        current_record.insertLine({
            sublistId: "item",
            line: i + 1
        });
        current_record.setSublistValue({
            sublistId: "item",
            fieldId: "item",
            line: i + 1,
            value: 24464,
        });
        current_record.setSublistValue({
            sublistId: "item",
            fieldId: "quantity",
            line: i + 1,
            value: 1,
        });
    }
c
add an && item_id to it.. so not only do you have to HAVE an item ID, it cant be equal to 24464 (which should also be a constant somewhere so you don't have magic strings in your code). Taking a guess that its seeing an empty item as != 24464 and adding a line
m
I've now added: const tax_item = '24464'; When I look at the internal ID's data type, it returns string, so my above const is a string. if (add_tax === true && item_id !== tax_item) still doesn't work - each edit to the order adds the line. I need a way to say, does the tax line already exists on the order, if so ignore the InsertLine