I'm trying to build a suitescript search for a pur...
# suitescript
m
I'm trying to build a suitescript search for a purchaseorder trying to get it to return it's associated sales order's entity value (joined via a custom field) but for some reason it's returning a tax agency instead?
Copy code
var poSearchResult = search.create({
          type: 'purchaseorder',
          filters: [['tranid', 'is', poNumber]],
          columns: [
            search.createColumn({
              name: 'entity',
              join: 'custbody_rsm_so_reference'
            })
          ]
        }).run().getRange(0, 1)[0]
returns
Copy code
JSON.stringify(poSearchResult.toJSON())
'{"recordType":"purchaseorder","id":"4157617","values":{"custbody_rsm_so_reference.entity":[{"value":"306","text":"Tax Agency DE"}]}}'
e
if you run a similar search in UI, do you not get the same result?likely due to the fact that it is not the Main Line Name
{mainname}
and therefore it is pulling the line name for that particular tax line or whatever it may be. trick is to run the search in UI and see what the results look like. try to limit also the search to main line is true, perhaps, for the associated sales order. that will eliminate this issue as well.
m
I wasn't able to figure out how to build the saved search, the fields it was giving me made no sense to me
e
in the ui?
m
Yep, even trying to figure out what the
tranid
field translates to didn't work
none of these 3 fields worked
e
tranid = Document Number
m
transaction number, transaction name/id, transaction number (text) all returned 0 documents
thank you ec,
Document Number/ID
finally worked
e
you need to refer to the suitescript records browser to figure out these connections
m
then accessing the SO Reference Fields list I don't see anything that says Entity
e
Name
or rather, I recommend Main Line Name
m
on a sales order,
Name
is the customer??
e
correct, however that will return different values for main/header vs lines
m
because nowhere in there does it say that tranid = Document Number
i refer to that schema browser constantly and I'd say 80% of the time it is frustratingly unhelpful
e
correct, not sure why. tribal knowledge. besides, you want to scroll down to bottom
but even here it reads “Number/ID” not sure why not Document Number, but that is what it is https://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2023_1/script/record/transaction.html
may i also suggest a chrome extension (assuming you are in chrome) for search export to script. this way, you can craft a saved search and inspect the suitescript equivalent. takes the guesswork out of it
i think it is called “NetSuite: Search Export 2.0”
m
Yeah I have that and it's why i was trying to build the saved search as well
just gave up because i couldn't figure out any of the field names/mappings and did a 2 step search
e
ok, so it should be relatively simple to build this search. you’ve got the means now?
m
Well, the problem for the moment is that i'm trying to test it with a single PO number, and so it's not giving me a list view result it's just sending me directly to the PO so I have no idea if the Results column i specified is correct since it won't show me results...
e
add
Document Number
= poNumber for the first filter. next,
SO Reference fields…
(join, bottom of list) should be filtered as well to Main Line = true. results: pull in
SO Reference fields…
(join, bottom of list) and then the sales order
Main Line Name
Go to preferences and turn that off (under analytics i believe: show results when only 1 result)
gotta go now but be in touch
m
Interesting, I was doing the PO main line - true
i copied it and i do think it actually works, thank you ec
essentially
Copy code
var purchaseorderSearchObj = search.create({
   type: "purchaseorder",
   filters:
   [
      ["type","anyof","PurchOrd"], 
      "AND", 
      ["numbertext","is","SCI948683"], 
      "AND", 
      ["mainline","is","T"]
   ],
   columns:
   [
      search.createColumn({
         name: "mainname",
         join: "CUSTBODY_RSM_SO_REFERENCE",
         label: "Main Line Name"
      })
   ]
});
e
👍
m
not quite sure how to access the value still
e
same, getValue({
Copy code
name: "mainname",
         join: "CUSTBODY_RSM_SO_REFERENCE"
})
m
oh i didn't know you could pass a join to getvalue
e
see the api docs, they are very helpful in this regard
now i gotta go
m
Yep, thanks for the help ec