I have a top 5 Items saved search which is i'm sor...
# suitescript
n
I have a top 5 Items saved search which is i'm sorting in descending order by Count so I can see Highest bought item top 5 items. I want to show that same saved search in a suitelet using Search.create. How I can sort it and show in the suitelet. I'm trying to add the sort.desc thingi but it is not working !! My Code:
var itemSearchObj = search.create({
type: "item", filters: [ ["transaction.type","anyof","VendBill"], "AND", ["displayname","isnotempty",""], "AND", ["displayname","doesnotcontain","arcutover"], "AND", ["subsidiary","noneof","17"], "AND", ["vendor.internalid","anyof",vendorName] ], columns: [ search.createColumn({ name: "displayname", summary: "GROUP", label: "Display Name" }), search.createColumn({ name: "salesdescription", summary: "GROUP", label: "Description" }), search.createColumn({ name: "custitem_company", summary: "GROUP", label: "Manufacturer" }), search.createColumn({ name: "tranid", join: "transaction", summary: "COUNT", sort: search.Sort.DESC, label: "Document Number" }) ] }); var searchResultCount = itemSearchObj.runPaged().count; log.debug("itemSearchObj result count",searchResultCount); var i=0; itemSearchObj.run().each(function(result){ if(i<5){ if(result.getValue({name: "displayname"})!='') outstandingOppoSublist.setSublistValue({ id : 'sublist_item', line : i, value : result.getValue({name: "displayname", summary: "GROUP"}) }); if(result.getValue({name: "salesdescription"})!='') outstandingOppoSublist.setSublistValue({ id : 'sublist_des', line : i, value : result.getValue({ name: "salesdescription", summary: "GROUP"}) }); if(result.getValue({name: "custitem_company"})!='') outstandingOppoSublist.setSublistValue({ id : 'sublist_make', line : i, value : result.getText({ name: "custitem_company", summary: "GROUP"}) }); if(result.getValue({name: "tranid"})!='') outstandingOppoSublist.setSublistValue({ id : 'sublist_count', line : i, value : result.getValue({name: "tranid", join: "transaction", summary: "COUNT",sort: search.Sort.DESC}) }); i++; } return true; });
b
not working can mean too many things, narrow it down with a more detailed explanation on what its doing
a quick look at the code suggests that you have a flawed mechanism for limiting your search to 5 results and that you have unnecessary empty checks, neither of which sounds like what you are describing
n
not working means, I'm not getting the top 5 items for the vendor which are bought highest. ex. if x item is bought 10 times from vendor v and y items is bought 7 times then x items should show first then y and then others which have less count!! right now I'm showing 5 items using i variable but those items are not having highest count!
please let me know if you got it?
t
You need to take a look at channel's description/topic. It just takes CTRL + SHIFT + ENTER . Code becomes more readable with that.
s
Copy code
outstandingOppoSublist.setSublistValue({
		  id : 'sublist_count',
		  line : i,
		  value : result.getValue({name: "tranid",
         join: "transaction",
         summary: "COUNT",sort: search.Sort.DESC})
try this bit without the sort?
Copy code
outstandingOppoSublist.setSublistValue({
		  id : 'sublist_count',
		  line : i,
		  value : result.getValue({name: "tranid",
         join: "transaction",
         summary: "COUNT"})
t
I would recommend to build the search in the UI and then load it via code, then all your sorting and info is separate from your code
b
probably need to look closer at what its doing
is it ignoring the sort? like does the code behave the same if you include sorting vs no sorting?
n
Yes it is ignoring the sort
b
Or is the sorting not what you expect, like doing lexicographical order vs numeric sort
n
In the search we can directly select the field and select sort by Descending... So it gets sorted but that is not working in code... I'm trying to show it on Suitelet! The Sort should be numeric! Since I want to show highest count row at top...
t
If you load the search via code the sort order should be maintained, no?
n
I think so... I'll be checking that..
b
the search module is not quite as good at the mimicking the ui as the other modules
one of the things that dont match is sorting, the ui is better at sorting numbers like counts as numbers, whereas the search module will look at column type to determine number vs string sorts
n
If the Loading search does not work... Any one have any idea for making it work??
b
nilesh says the sort is ignored, and not lexigraphical, so thats probably not the problem
What do your search results look like ?
n
you can see the search top count on right side of the search!
b
That looks the actual saved search, i meant the suitelet
n
here
I'm just using a variable to count to 5 and if condition to get 5 records but these are not top 5!
b
One of the statements you told us is false
Ill give a minor hint and say that your results are sorted
Figure out how and you will have a good idea of what you need to fix
n
Untitled
I was trying to work it using loading that search but it is showing blank!! the suitelet is showing blank for the selected vendor
b
vendor.internalid is not the name of a column
Dont confuse the syntax of a filter expression with that of a filter
n
Loading of saved search is also not working
Untitled
tried loading it but it still gives result like before when I tried to create saved search in code itself
b
its not your problem
you will want to start going through my previous responses
n
my results are not sorted mate
see
b
sorted
might not be how you want it sorted, but that is sorted
n
I mean it should give me highest count at the top right?
like bubble sort
b
go through my previous responses, thats not the behavior of the search module
n
so I need to develop a logic to get what I need , search module can't do it right?
b
it can
n
how? search.sort.desc?
b
do you understand the behavior?
n
yah
b
of the script module concerning sorting and column types?
n
columns[3].sort = "DESC";
I tried this, but not working
b
thats not going to do anything more than what you have already done
n
i really don't understand how to sort it then I think😅
using search modul!
@battk went through your previous responses, didn't get the hint/solution? can you please help me with that?
n
you mean search module doesn't support it I have to use my coding logic to sort it right?
b
the message after that one
n
i got that but I couldn't get how to resolve it now?
b
tranid is a text column
so it uses a text based sort
use a column that isnt text
n
ohk you mean the count column is a text column ? if I convert that to numeric then it will work right?
b
i mean that tranid is a text column, so the search module will sort it as text
you dont want to use a text column to do a numeric sort
n
what if I use internal id of that tran id?
since I'm using summary : Count , it should take the count into consideration right? but search module doesn't work that way I think!
Thanks @battk it is working when I use internal ID! Thank you very much🙂
151 Views