Using a SuiteQL query `.asMappedResults` , can I g...
# suiteql
a
Using a SuiteQL query
.asMappedResults
, can I get the type of the record like by
N/search
for record loading purposes afterwards?
c
Since a query can join multiple record types, it's up to you to determine what you want it to output. You can do something like
Copy code
SELECT
  id,
  tranid,
  'myType' AS my_type
FROM transaction
where 'myType' can be either static or determined by logic per your demands
s
The results for
type
in queries (and searches) are not exactly equal to the
record.Type
enum, it's likely going to need a manual mapping
c
Yep, which is why I'm suggesting to manually cast it. I probably picked the wrong label in the word
type
😄 Edited to fix that
b
there should be a recordtype column that you should be able to add to your query
c
@battk I don't see that column on all tables in the Analytics browser - is it an undocumented column available everywhere?
b
out with the old, in with the new
c
@battk Yeah I haven't started delving into the Records Catalog yet; however, just now on checking, I dont see record type on a few tables there either 🤔
b
there is a search field for the fields
c
Correct, and using that and also selecting a couple of tables at random, I see that the column doesn't appear in all tables. I'm just wondering if it's something supported in all tables but not documented, like a lot of things Netsuite-ish
a
When running a
N/search
on item from a map/reduce, I wanted to load the record for each result in the map stage. I was able to get what type of item I was loading (inventory, non-inventory etc...) by using search.type I know that search and record enums are not necessarily identical, but for that case it did what I needed, differentiating between item types. There is no built in way in query to do that?
I have to manually do that?
Meaning if I query item.itemtype I get
Non Invntry Part
nothing near the string representation of the enum
So I would need to get that field and map all the possible results to the corresponding enum?
b
recordtype is not a generic column
it would help you on transactions
a
Well that is the first reason I see to go with search over query
b
for items, you probably have to do your map
or if you are extra lazy, a lookup
c
@Azi How many rows are you working with?
a
Anywhere between 10 and 500
c
Aside from rolling your own map between N/query's itemtype and the record.Type enum, the only other way I can see to use N/query for your dataset and get record.Type values to load records would be to do a search.lookupFields on each row of the resultset to get the recordtype. At that point, you might as well just use N/search to begin with, unless there are other constraints preventing you from doing so.
Unfortunately, the
itemtype
table won't get you there: for example, it maps Assembly to Assembly, which isn't the record.Type enum value of assemblyitem