Sorry, I made a lot of errors that I didn't think ...
# suitescript
m
Sorry, I made a lot of errors that I didn't think it would make any sense. Here's my code that is throwing an error:
Copy code
var lines = currentRecord.getLineCount({
    sublistId: 'component'
});
log.debug({title: "Lines", details: lines});//Returns 2 - correct

var component_details = currentRecord.getSubrecord({
    fieldId: 'component'
}); //ERROR

for (var x = 0; x < lines; x++) {
    var item_name = component_details.getSublistValue({
        sublistId: 'component',
        fieldId: 'item',
        line: 0,
    })

    log.debug({title: 'Item', details: item_name});
}

Field component is not a subrecord field
I am running this on Assembly Build. I am trying to access the inventory details in the Component sublist
Getting the line count now but getting an unexpected error:
Copy code
var rec = record.load({
    type: record.Type.ASSEMBLY_BUILD,
    id: ab_id,
    isDynamic: true
});

var lines = rec.getLineCount({
    sublistId: 'component'
});
log.debug({title: "Lines", details: lines});

var component_details = rec.getCurrentSublistSubrecord({
    sublistId: 'component',
    fieldId: 'componentinventorydetail'
});
b
dynamic mode requires you to select which line is the current one
m
selectLine? this isn't available on my rec object
message has been deleted
b
take your pick, do you trust the docs or the autocomplete
m
Is the selectLine pointing to the current Component? So something like this:
Copy code
var lines = rec.getLineCount({
    sublistId: 'component'
});
log.debug({title: "Lines", details: lines});

rec.selectLine({
    sublistId: 'component',
    line: 0
});

var component_details = rec.getCurrentSublistSubrecord({
    sublistId: 'component',
    fieldId: 'componentinventorydetail'
});
log.debug({title: "component_details", details: component_details});

for (var x = 0; x < lines; x++) {
    var item_name = component_details.getSublistValue({
        sublistId: 'component',
        fieldId: 'item',
        line: x,
    })
b
you dont mix getSublistValue and getCurrentSublistValue
or any of the related methods
getCurrentSublistValue is used with dynamic mode
dynamic mode mimics the ui where you select lines
standard mode (not dynamic) does not, you can use getSublistValue to get values without worrying about which line is selected
m
I think I am now correctly looping through the lines - the line count is 2 which is correct and I am able to log the quantity. But if I wanted to know go inside the inventory details, would I need to do another loop?
b
depends on which inventory details
if you mean the body level inventory detail., then no
if you mean the component level inventory detail, then you would need to use a loop
though you dont necessarily need a new one, you can probably reuse your existing one
m
Component level inventory - I'll try and see if I can reuse the first loop
tried with two loops but doesn't seem to give me any data back for the fields except the quantity and i am not sure if the quantity shown is only for the component line and not the component inventory line
Copy code
var component_details = rec.getCurrentSublistSubrecord({
    sublistId: 'component',
    fieldId: 'componentinventorydetail'
});
log.debug(component_details);

var inv_detail = rec.getSubrecord({
    fieldId: 'inventorydetail'
});
log.debug(inv_detail);

for (var x = 0; x < lines; x++) {
    log.debug("Z");
    var quantity = component_details.getCurrentSublistValue({
        sublistId: 'inventoryassignment',
        fieldId: 'quantity',
        // line: x,
    });
    log.debug({
        title: 'Quantity', details: quantity
    });
    var item = component_details.getCurrentSublistValue({
        sublistId: 'inventoryassignment',
        fieldId: 'compitemname',
    });
    log.debug(_item);
    for (var y = 0; y < lines; y++) {
        log.debug("2nd Loop");
        var _quantity = inv_detail.getCurrentSublistValue({
            sublistId: 'inventoryassignment',
            fieldId: 'quantity',
        });
        log.debug(_quantity);

        var _item = inv_detail.getCurrentSublistValue({
            sublistId: 'inventoryassignment',
            fieldId: 'compitemname',
        });
        log.debug(_item);
    }
}
b
i dont see you selecting lines anywhere
you arent actually looping over different lines since you never select a different line
your code basically processes the same thing over and over again
and while its not an issue now since your loops are useless, the for loop that uses x as its index is indexing against the lines variable, which contains the number of lines of the component sublist
the x loop looks like its trying to loop over the lines of the inventory assignment, whichs means you are indexing against the wrong line count
there is little relation between the number of lines of the component sublist and the number of lines of the inventory assignment sublist
you also have a loop on the body level inventory detail, which makes the same mistake, and probably shouldnt be nested in the x loop
m
I realised I missed this bit out from the above:
Copy code
var rec = record.load({
    type: record.Type.ASSEMBLY_BUILD,
    id: ab_id,
    isDynamic: true
});

var lines = rec.getLineCount({
    sublistId: 'component'
});
log.debug({title: "Lines", details: lines});
rec.selectLine({
    sublistId: 'component',
    line: 0
});
the select line is there for the component so I should have another for the inventoryassignment