Is there a reason why this search wouldn’t work? `...
# suitescript
j
Is there a reason why this search wouldn’t work?
Copy code
var itemSearchObject = search.create({
	type: 'item',
	filters: [
		['custitem_associated_item.isonline','is','T'],
		'AND',
		['custitem_associated_item.isinactive','is','F'],
		'AND',
		['custitem_associated_item.custitem_closeoutitem','is','T'],
		'AND',
		['inventorylocation.makeinventoryavailablestore','is','T'],
		'AND',
		['inventorylocation.isinactive','is','F']
	],
	columns: [
		search.createColumn({
			name: 'type'
		}),
		search.createColumn({
			name: 'parent',
			join: 'CUSTITEM_ASSOCIATED_ITEM',
			summary: 'GROUP',
			label: 'Parent'
		}),
		search.createColumn({
			name: 'locationquantityavailable',
			summary: 'SUM',
			label: 'Location Available'
		})
	]
});

itemSearchObject.run().each(function(result){

	// do stuff

	return true;
});
I’m not very experienced with joins and functions within search results, but any time I add the column for the item type, things go haywire and I just get an
UNEXPECTED_ERROR
. Any idea as to what would be the problem here?
c
Easiest thing to do is create the search in the UI & then export it using the chrome plugin that generates the code for you
j
@CD That’s what I did…
c
Lol 😂 facepalm
j
The only columns it creates are
parent
and
locationquantityavailable
I think it’s because those are the only two columns that show in the search results. I might have to change up my approach here…
s
Well you should probably just remove the type column, since your results are summarized, its doing nothing. If you want the item type, then you need to create a column similar to
parent
and grab
type
instead
j
@Sandii Yeah, it just kinda figured that out. Can I get
parent
and
type
?
s
What do you want the type of, the item or its parent? If you want the type of the item, you can get it the exact same way you get parent. If you want the type of the parent, then you need to go to
N/query
since its a double level join.
j
Oh, yeah, i guess I need the type of the associated item, so will probably have to use
N/query
. Crap…
s
Not sure I follow here, you have item (base record), then you have a field called
associated item
, the type of the associate item would be (assuming its an item record)
Copy code
search.createColumn({
			name: 'type',
			join: 'CUSTITEM_ASSOCIATED_ITEM',
			summary: 'GROUP',
			label: 'Parent'
		})
currently you are grabbing the parent of the associated item
j
@Sandii Yes, I’ve figured that part out, but it seems to return a string rather than a record type. Is there a way to return the record type? I need to reference the record type later, but it has to be a record type enum.
s
You can’t/don’t get record type enums from saved searches, gonna have to manually transform it
Record type enums are just strings, it’s a pretty simple mapping since there shouldn’t be too many choices