I need a user event script to run a search for oth...
# suitescript
c
I need a user event script to run a search for other invoices with the same ship-to address, but I can't get the search to identify a match between existing ship-to's and the value pulled from the invoice. The search below has 0 results, which should not be the case.
Copy code
var shipDate = context.newRecord.getValue({ fieldId: 'shipdate' })
var shipAddress = context.newRecord.getText({ fieldId: 'shipaddress' })

search.create({
    type: "invoice",
    filters:
        [
            ["type", "anyof", "CustInvc"],
            "AND",
            ["mainline", "is", "T"],
            "AND",
            ["shipdate", "on", shipDate],
            "AND",
            ["shipmethod", "anyof", "69"],
            "AND", 
            ["shipaddress","is", shipAddress],
            "AND",
            ["anylineitem", "anyof", "15942"]
        ],
    columns:
        [
            search.createColumn({ name: "entity", label: "Name" }),
            search.createColumn({ name: "shipaddress", label: "Shipping Address" })
        ]
}).run()
I'm sure this is a data type or formatting issue. Anyone have any advice on how to format the address either in the script or in the search to get them to match?
Changing the filters to get results then logging the value from the record and search look similar, but the search will not recognize them as a match under the ["shipaddress","is", shipAddress] filter
message has been deleted
I guess I can't take the easy way out, I'll just have to break the address down into its individual components and compare those:
Copy code
var shipAddr1 = context.newRecord.getText({fieldId: 'shipaddr1'})
        var shipAddr2 = context.newRecord.getText({fieldId: 'shipaddr2'})
        var shipAddr3 = context.newRecord.getText({fieldId: 'shipaddr3'})
        var shipCity = context.newRecord.getText({fieldId: 'shipcity'})
        var shipState = context.newRecord.getText({fieldId: 'shipstate'})
        var shipZip = context.newRecord.getText({fieldId: 'shipzip'})
        search.create({
            type: "invoice",
            filters:
            [
               ["type","anyof","CustInvc"], 
               "AND", 
               ["mainline","is","T"], 
               "AND", 
               ["shipdate","on",shipdate], 
               "AND", 
               ["shipmethod","anyof","69"], 
               "AND",
               ["anylineitem","anyof","15942"], 
               "AND", 
               ["shippingaddress.address1","is",shipAddr1], 
               "AND", 
               ["shippingaddress.address2","is",shipAddr2], 
               "AND", 
               ["shippingaddress.address3","is",shipAddr3], 
               "AND", 
               ["shipcity","is",shipCity], 
               "AND", 
               ["shipstate","anyof",shipState], 
               "AND", 
               ["shipzip","is",shipZip]
            ],
            columns:
            [
               search.createColumn({name: "entity", label: "Name"}),
               search.createColumn({name: "shipaddress", label: "Shipping Address"})
            ]
         }).run()
a
instead of getting the text from the shipaddress field you should be able to get the address id with get value from the shipaddresslist then you can just use that as the search filter shippingaddress join like you're doing in your second code block, but with a single filter instead of 1 per address line
(I haven't tested this, but it should work in theory)
c
The only issue I had with using internal id's is that custom addresses will have a different internalid for duplicates
a
yeah that's true
then i think your approach 2nd approach is the only way to do it, ship address isn't a real field its a summary field so you can't filter on it directly
c
I just figured that out, yeah. Had to get the values from the subrecord instead of the invoice record
a
you might still have an issue if ppl have entered custom duplicate addresses, but differed slightly in terms of case usage, and abbreviations Dr. vs Drive vs dr. vs dr Suite XXX vs Ste. XXX etc. etc.
c
True, I'm still debating on how much validation I want to incorporate. I might just wait and see if that happens. Then when a user complains my advice might just be "Don't do that"
👍 2
😂 1