Any general idea on how to access the location ave...
# suitescript
l
Any general idea on how to access the location average cost from the item record? I need to grab the location average cost from the item record on pageInit based on the default location on each transaction line of the item receipt. I'm confused by the Record.getSublistValue since it requires a "line". How can I know the line number of the location selected in the IR? On the UI, the locations can be sorted alphabetically.
p
Hi @Luis - I think you need to do a search to get that; I don't think you can load any of the related records for to get the location's average cost. I don't see the field anywhere in the Records Browser, which should be the first thing you look at for things like this. (Items do have an Average Cost, but that's per-Item, not per-Item and Location.)
t
you can use the "getCurrentSublistValue" just specify the sublist and the fieldname then it will return the value needed
l
Let's say the sublistId is locations and the fieldId is locationaveragecost, then how can I pick the locationaveragecost related to the selected location only in the Item Receipt?
@Peter Ries this sounds right. Do you have any idea where I can get a sample that's close to what I need? Thanks.
t
the fieldId you should encode on this is the one that holds the value you needed
l
@Tyn Guardian I believe that's the locationaveragecost. However, there are a lot of locations in that sublist. I only want to grab the one that is the same with the Item Receipt line location.
b
alternatively use Record.getSublistValue on every line until you find the location you are looking for
l
It logs -1 when I use the findSublistLineWithValue. Maybe because there is no unique line number?
t
-1 means that there is no value on your sublist. Maybe you have encoded the wrong sublistId. Try to inspect element the sublistId then check the id of your sublist
b
you can try sharing your code, but Record.findSublistLineWithValue doesnt care about uniqueness
and each row in the locations sublist has a unique location
l
NetSuite support said that it can't be accessed through that. But thank you. Instead, I tried using the n/search module but I can't still make it work:
Please ignore the incomplete log.debug.
b
your code likely does not do what you want it to do
it will get the location average cost from the last search result, and try to set that on all your lines
t
Also, using saved search to get a field on your line item is not a solution. The governance allocated for search and how much it took on your process. I won't advise it