如何使用 search.lookupFields() 进行联合查找?
How do I do a joined lookup with search.lookupFields()?
我正在尝试获取有关某个项目的一些信息,包括该项目的子公司徽标,这自然需要将项目加入子公司。
search.lookupFields
的文档说:
You can use joined-field lookups with this method, with the following syntax:
join_id.field_name
所以,我正式请求我想要的字段,包括 subsidiary
:
上的连接
require(['N/search'], function(search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary.logo'],
});
log.debug(item);
});
itemid
和 displayname
很好,但是当我尝试加入另一条记录时出现此错误:
{
"type":"error.SuiteScriptError",
"name":"SSS_INVALID_SRCH_COLUMN_JOIN",
"message":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"stack":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"cause":{
"type":"internal error",
"code":"SSS_INVALID_SRCH_COLUMN_JOIN",
"details":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"userEvent":null,
"stackTrace":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"notifyOff":false
},
"id":"",
"notifyOff":false,
"userFacing":false
}
无论我尝试加入哪个记录和字段,这似乎都会发生。我错过了什么?
我相信您无法从查找字段访问附属记录,您应该进行适当的搜索。
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2018_2/script/record/item.html
您只能加入项目搜索对象中允许的表。尝试在 UI 的“搜索结果”选项卡中查找 "Subsidiary..."。它不在那里。使用架构浏览器确定可用的字段和连接。
您不能将 NetSuite 搜索想象成任何常规 SQL 搜索。您必须了解可以通过搜索对象使用哪些字段和哪些连接。
这不会回答您的问题,但将来可能会有所帮助。记录浏览器显示您可以搜索和加入的所有内容、列和过滤器以及字段 ID。在构建搜索时非常有用。
正如人们所提到的,子公司不是项目记录中可用的连接字段,实现您正在尝试做的事情的一种方法是:
- 进行查找以获取属于所需项目的子公司的内部 ID。
- 然后查找上一个子公司的logo图片(文件柜图片)的内部id。
- 制作另一个 lookup/load 图像文件以获得 image/logo
的 URL
您可以尝试将上述步骤合并到一个已保存的搜索中,但我认为您可能需要加载图像文件才能获得 URL。
尽管您可以从 multi-select 个字段中获得 return 个结果,但您不能加入 multi-select 个字段引用的记录中的字段(项目记录中的子字段是)。此外,您无法搜索子公司记录上的徽标字段(未在 NetSuite 记录浏览器的子公司下的搜索列中列出)。
这意味着您必须加载子公司记录才能获取徽标字段。换句话说:
require(['N/record', 'N/search'], function(record, search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary'],
});
var subID = item.subsidiary[0].value; //internal id of *first* subsidiary
var subRec = record.load({
type: record.Type.SUBSIDIARY,
id: subID
});
var logo = subRec.getText('logo'); //gets the file name - use getValue to get its ID instead
});
请注意,如果在项目上设置了多个子公司,这只会获取第一个的值。如果需要,您可以遍历 item.subsidiary
结果以处理多个子公司的值。
我正在尝试获取有关某个项目的一些信息,包括该项目的子公司徽标,这自然需要将项目加入子公司。
search.lookupFields
的文档说:
You can use joined-field lookups with this method, with the following syntax:
join_id.field_name
所以,我正式请求我想要的字段,包括 subsidiary
:
require(['N/search'], function(search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary.logo'],
});
log.debug(item);
});
itemid
和 displayname
很好,但是当我尝试加入另一条记录时出现此错误:
{
"type":"error.SuiteScriptError",
"name":"SSS_INVALID_SRCH_COLUMN_JOIN",
"message":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"stack":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"cause":{
"type":"internal error",
"code":"SSS_INVALID_SRCH_COLUMN_JOIN",
"details":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"userEvent":null,
"stackTrace":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"notifyOff":false
},
"id":"",
"notifyOff":false,
"userFacing":false
}
无论我尝试加入哪个记录和字段,这似乎都会发生。我错过了什么?
我相信您无法从查找字段访问附属记录,您应该进行适当的搜索。
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2018_2/script/record/item.html
您只能加入项目搜索对象中允许的表。尝试在 UI 的“搜索结果”选项卡中查找 "Subsidiary..."。它不在那里。使用架构浏览器确定可用的字段和连接。
您不能将 NetSuite 搜索想象成任何常规 SQL 搜索。您必须了解可以通过搜索对象使用哪些字段和哪些连接。
这不会回答您的问题,但将来可能会有所帮助。记录浏览器显示您可以搜索和加入的所有内容、列和过滤器以及字段 ID。在构建搜索时非常有用。
正如人们所提到的,子公司不是项目记录中可用的连接字段,实现您正在尝试做的事情的一种方法是:
- 进行查找以获取属于所需项目的子公司的内部 ID。
- 然后查找上一个子公司的logo图片(文件柜图片)的内部id。
- 制作另一个 lookup/load 图像文件以获得 image/logo 的 URL
您可以尝试将上述步骤合并到一个已保存的搜索中,但我认为您可能需要加载图像文件才能获得 URL。
尽管您可以从 multi-select 个字段中获得 return 个结果,但您不能加入 multi-select 个字段引用的记录中的字段(项目记录中的子字段是)。此外,您无法搜索子公司记录上的徽标字段(未在 NetSuite 记录浏览器的子公司下的搜索列中列出)。
这意味着您必须加载子公司记录才能获取徽标字段。换句话说:
require(['N/record', 'N/search'], function(record, search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary'],
});
var subID = item.subsidiary[0].value; //internal id of *first* subsidiary
var subRec = record.load({
type: record.Type.SUBSIDIARY,
id: subID
});
var logo = subRec.getText('logo'); //gets the file name - use getValue to get its ID instead
});
请注意,如果在项目上设置了多个子公司,这只会获取第一个的值。如果需要,您可以遍历 item.subsidiary
结果以处理多个子公司的值。