Is there a function in NFT that handles duplicate ...
# suitescript
c
Is there a function in NFT that handles duplicate line items i.e. assume a fulfillment JSON message comes in with a SKU/item name but the item sublist has multiple lines with the same SKU? I have my own helper function but I can't help wonder if someone has come up with something better?
s
NFT doesn't have general utility functions (by design) - it instead enables popular existing libraries like lodash and you can then easily find answers on the intertubes. https://stackoverflow.com/a/28461122
if you want to do something else with the dupes other than detect them, there's probably a battle tested lodash function for that as well.
c
@stalbert yeah I just need to make sure I am fulfilling the correct line in the absence of a unique ID coming back from the WMS
Added complexity of lot numbering
s
you'll have to come up with the logic of how to find the line you want to use but it sounds like
Copy code
const found = _.find( fulfillment.item, line => // your logic to find the desired line here)
b
the duplicate concern suggests that there are multiple lines that will match each item from the json
c
@battk that's exactly right
I don't think it's possible to find a single line in this scenario
so I could add all duplicate items to a list then iterate through each one, fulfilling each ones committed qty, until the fulfilled number (in the JSON) is zero.
s
lodash would still be your friend there
but I realize some folks love writing iteration by hand. 🙂