Morning All. So i am using `.setWhenOrderedBy` on ...
# suitescript
k
Morning All. So i am using
.setWhenOrderedBy
on a search.Column but the docs are saying that the join option is required?
Copy code
columns[1].setWhenOrderedBy({
name: 'trandate',
join: 'transaction'
});
l
I just read the docs. Are you running a customer search and then joining to the transaction record like in the example?
I don't understand why the docs don't show this being used on a transaction search directly, you wouldn't need a join then (though you are right, it says it's required).
k
That's what is throwing me. I checked @erictgrubaugh Search documentation and he mentiones just to put
join: 'x'
but doesnt seem to work.
I'm wondering whether i need to have the trandate column in there as a column as well.
l
Would join '@NONE@' work?
Just throwing something out to see if it sticks... no reason why it would work.
e
setWhenOrderedBy
is definitely buggy in 2.0; pretty sure @creece and @errol have been running into trouble with it lately
e
@karlenigma definitely odd that join is *required*… i see no reason it should be. However as @erictgrubaugh mentioned, there is definitely a bug in 2.0 when running searches that use the “when ordered by” function. I have only used it in script indirectly, for example I loaded an existing search and ran it. In 2.0 though, I found that the results where not being returned correctly and different than running it in the UI.
it may work if you directly set and use setWhenOrderedBy in script, but it seems they didn’t fully think it through as they required a join field.
k
I have it on my script and defo doesn't work. Going to go down the search.load tomorrow and see it I can get my script to work that way.
e
Just be careful with it using search.load. That I know for a fact was returning incorrect results. So be sure to check that. What I was seeing was that the number of results was correct, but the values in the column that was using “when ordered by” were not accurate. Running the same search in the UI shows the correct results.
c
It doesn't work when you load the search either. I can confirm that. I tried in both search.load and search.create and neither behaved correctly when using that function.
k
How did you get around it @creece. As without using the search as it is in the UI I have little to no idea.
c
I super wizard i work with wrote the search differently
k
Hmmm don't think that will happen might have to stick with running the search and only doing it for max 75 items.
Running the search 75 times lol
c
You may not have to do that if you can re-write the search but if you don't set when ordered by, you can set your sorts appropriately and loop through them
I was about to go down that route before my coworker figured out the seardh
if you just use MAX instead, you'll get more results, but the 1st one SHOULD be the latest if thats what you're going for.. if you group by a certain ID you can loop through results and track the ID and when you hit a new ID, grab the 1st result as the latest.. something similar to that