Tip: Use JavaScript to filter on a value in a record array

Comments

2 comments

  • PSA Admin

    Thank you, Tom! Question: is the filter either J-Script or Rule but not both? I'm guessing that's they are mutually exclusive, but just wanted to verify.

    Jim

    0
  • Jolyon Blazey
    Celigo University Level 2: Seasoned

    I am pretty sure you can only use one or the other not both.

    Thanks for this helpful code, this is an alternative filter searching for different criteria using reduce()

    function filterIncludeReturnShipping (options) { 
    if (!options.record || !options.record.line_items) {
    return false
    }
    const returnWillBeShippedToWarehouse = 'default'
    const initialValue = false

    return options.record.line_items.reduce((accumulator, currentValue) => {
    return accumulator || (
    options.record.state === "open" && currentValue.outcome === returnWillBeShippedToWarehouse
    )}, initialValue)
    }
    0

Please sign in to leave a comment.