I have a List/Record field on a custom record that...
# suitescript
r
I have a List/Record field on a custom record that is sourced from two different record types (Quote, Sales Order). Within a Suitelet, I am using
N/search.lookupFields()
to pull that value (along with several others) from the record. I then need to to lookup additional data from whatever that record is. The issue I'm running into is that because it's one of two possible record types, I don't have a clean programmatic way to pull the record type.
N/search.lookupFields()
returns
Copy code
{"custrecord_fq_linked_transaction":[{"value":"267972","text":"Sales Order #SO35426"}]
I can do a text-search within the
.text
key for
Sales Order
or
Quote
but that feels very unclean. Closest googling came was this reddit post which talked about an undocumented
.type
key, but that's based on using
N/record
, which I'm trying to avoid loading the entire record when
N/search
will just get me the data. Anyone have any ideas how to get record type using
N/search.lookupFields()
?
b
search.lookupFields is basically a search, and has access to Result.recordType in the
recordtype
column
r
thanks. That got me part of the way there.
Copy code
let freightQuoteData = Nsearch.lookupFields({
	type: uvFQLibId.record.FREIGHT_QUOTE.id,
	id: params.fqIid,
	columns: [
	    freightQuoteField.LINKED_TRANSACTION,
	    freightQuoteField.LINKED_TRANSACTION + '.type',
	],
});
gives me
Copy code
{
  "custrecord_uv_fq_linked_transaction":[{"value":"267972","text":"Sales Order #SO35426"}],
  "custrecord_uv_fq_linked_transaction.type":[{"value":"SalesOrd","text":"Sales Order"}],
}
problem now is
SalesOrd
is not in the enum of
N/record.Type
, as it uses
salesorder
. I cant find any info on a native translation from what the
.type
property returns to what is accepted by a param requiring
N/record.Type
enum. I also tried your
.recordtype
, but that didn't return the type of the linked transaction, but the type of the record the lookup was being performed on
b
you need to actually specify recordtype in the columns
and just like a regular search, it wont give the type of a join, its the record type of the search result
r
I may have poorly explained myself. `customrecord_uv_fq`: custom record
custrecord_uv_fq_myfield
is a custom field on that record of type List/Record, sourced only from record types of either Quote or Sales Order. When I do the following:
Copy code
Nsearch.lookupFields({
	type: 'customrecord_uv_fq',
	id: 123,
	columns: [
	   'custrecord_uv_fq_myfield',
	   'custrecord_uv_fq_myfield.type',
	],
});
I'm trying to get the record type of which record is linked in the custom field, so then I can then to a subsequent lookup on that record.
but since that custom field could contain multiple record types, I can't seem to identify which record type is in the custom field, only the internal id of the record
b
if you are just going to do another lookup on the transaction, then you should just use the join
for example, if you were trying to get the memo of the linked transaction, then you would do
custrecord_uv_fq_myfield.memo
if you really wanted to load the record for use in N/record, then i personally would write code that transforms
SalesOrd
into
salesorder
, especially if you only have to do it for sales orders or quotes
r
the challenge is that depending on the linked transaction type, I have to lookup different fields.
I can add my own transform form
SalesOrd
=>
salesorder
, I didn't know if there was a native transformation, or there was a way of getting
salesorder
from the original lookupsearch
b
searches dont treat sales orders or quotes differently, they are both transactions with the same set of columns
so you just make add more to your columns array to handle both types
r
that I understand. If it was a native field used on both transactions it wouldn't be an issue.
b
there is no such thing as a custom sales order field or custom quote field
r
sorry, poor wording on my part.
If Sales ORder, then lookup secondary x, y, z. If Quote, then lookup secondary a, b, c.
b
they are both transaction body fields, and actaully are the same column in a transaction search
r
so I could just add x, y, z, a, b, c to the initlal lookup, and then just grab which ones I'm going to use based on the return type
b
dont write two different lookups, just write if transaction, then lookup x,y,z,a,b,c
👍 1
r
appreciate the insight. learned under the paradigm of "only query what you need when you need it", which causes me problems with SuiteScript sometimes