英文:
netsuite suiteScipt 2.0 Search: is there a way to filter by nested object keys?
问题
Here's the translation of your provided code:
尝试在NetSuite中编写一个Restlet,并按嵌套键进行过滤,但似乎无法解决它
var f1 = search.createFilter({
name: 'salesrep.id',
operator: search.Operator.IS,
values: '77'
});
var filter;
var id;
if (context.closerId) {
filter = 'custentity_bb_sales_rep_employee';
id = context.closerId;
} else if (context.setterId) {
filter = 'custentity_ss_setter_employee';
id = context.setterId;
}
var mySearch = search.create({
type: search.Type.CUSTOMER,
columns: ['entityid', 'firstname', 'lastname', 'salesrep', 'custentity_ss_setter_employee', 'custentity_bb_sales_rep_employee', 'custentity_bb_home_owner_phone', 'custentity_bb_install_address_1_text', 'custentity_bb_install_city_text', 'custentity_bb_install_state', 'custentity_bb_install_zip_code_text'],
filters: [f1],
});
Please note that I've only translated the code portion, as you requested. If you have any specific questions or need further assistance, feel free to ask.
英文:
Trying to write a restlet in netsuite and filter by a nested key, however I can't seem to crack it
`
var f1 = search.createFilter({
name: 'salesrep.id',
operator: search.Operator.IS,
values: '77'
});
var filter;
var id;
if(context.closerId) {
filter = 'custentity_bb_sales_rep_employee';
id = context.closerId;
} else if (context.setterId) {
filter = 'custentity_ss_setter_employee';
id = context.setterId;
}
var mySearch = search.create({
type: search.Type.CUSTOMER,
columns: ['entityid', 'firstname', 'lastname', 'salesrep', 'custentity_ss_setter_employee', 'custentity_bb_sales_rep_employee', 'custentity_bb_home_owner_phone', 'custentity_bb_install_address_1_text', 'custentity_bb_install_city_text', 'custentity_bb_install_state', 'custentity_bb_install_zip_code_text' ],
filters: [f1],
});````
heres the code I'm trying and yet its not working, I'm wondering if there even is a way to filtter by salesrep.id
I've tried pretty much everything in the documentation, not sure where to go from here
</details>
# 答案1
**得分**: 1
不,没有办法在过滤器中使用任意的“嵌套属性”。
但是,NetSuite支持搜索连接的概念。
根据我的经验,您需要使用NetSuite记录浏览器,查看特定记录类型上可用的连接以及它们引用的内容(引用的记录是什么),然后您可以使用所引用记录的某些(而不是所有)属性。
例如,您想查找所有客户记录,其销售代表引用记录的ID为'77'。
所以您打开NetSuite记录浏览器: https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2022_1/script/record/customer.html
并查看它支持哪些连接:
[NetSuite记录浏览器截图][1]
确实,它支持销售代表连接,并引用Employee记录类型。所以您转到Employee https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2022_1/script/record/employee.html 查看它支持哪些搜索过滤器,然后使用那些过滤器(来自“连接”的记录)。您会看到没有“id”搜索过滤器,而是“internalid”,这可能是您需要的:
[NetSuite记录浏览器上的Employee记录页面][2]
所以这段代码(原始的):
//this is wrong:
var f1 = search.createFilter({
name: 'salesrep.id',
operator: search.Operator.IS,
values: '77'
});
必须是(请注意值属性中的数组文字,我不确定在您的原始示例中的字符串是否有效):
var f1 = search.createFilter({
name: 'internalid',
join: 'salesrep',
operator: search.Operator.IS,
values: ['77']
});
我不确定您的代码是否有效,因为它有点凌乱,但是过滤器应该是正确的。
[1]: https://i.stack.imgur.com/OMBW5.png
[2]: https://i.stack.imgur.com/dp9lp.png
<details>
<summary>英文:</summary>
No, there is no way to use arbitrary 'nested properties' in the filters.
But, NetSuite supports the concept of a search join.
From my experience, you need to use NetSuite records browser, to see which joins are available on a particular record type and what they refer to (which record), then you can use some (not every) property of the referred record's.
E.g. you want to find all the cusomer records, which have their salesrep referred record's id as '77'.
So you open the NetSuite records browser: https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2022_1/script/record/customer.html
And see which joins does it support:
[![NetSuite records browser screenshot][1]][1]
Indeed, it does support the salesrep join and it refers to the Employee record type. So you go to the Employee https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2022_1/script/record/employee.html to find which Search Filters it supports, and you use those filters (from the 'joined' record). You'll see that there is no 'id' search filter, but instead there is 'internalid', this must be what you need:
[![Employee record page from NetSuite records browser][2]][2]
So this piece of code (the original one):
//this is wrong:
var f1 = search.createFilter({
name: 'salesrep.id',
operator: search.Operator.IS,
values: '77'
});
must be (**also please not the array literal** in the values property, I'm not sure if a string, as in your original example will work)
var f1 = search.createFilter({
name: 'internalid',
join: 'salesrep',
operator: search.Operator.IS,
values: ['77']
});
I'm not sure if your code will work, since it's a bit messy, but the filter should be correct
[1]: https://i.stack.imgur.com/OMBW5.png
[2]: https://i.stack.imgur.com/dp9lp.png
</details>
# 答案2
**得分**: 0
I'm not sure what you mean by "nested object keys," but there is a simple solution for your example of filtering by 'salesrep.id' - you simply specify it as 'salesrep'.
search.createFilter({
name: 'salesrep',
operator: search.Operator.ANYOF,
values: '77'
})
Note also that for List/Record (select/dropdown) fields, you should use the ANYOF operator rather than IS.
Further comments: if by "nested object keys" you are referring to values that come from record joins, then you can use the `join` property of the `search.createFilter(options)` options parameter. For example, if you wanted to use the sales rep's name instead of the internal id, you could do:
search.createFilter({
join: 'salesrep',
name: 'entityid',
operator: search.Operator.IS,
values: 'Tom Sawyer' //Put the sales rep's name here
})
<details>
<summary>英文:</summary>
I'm not sure what you mean by "nested object keys", but there is a simple solution for your example of filtering by 'salesrep.id' - you simply specify it as 'salesrep'.
search.createFilter({
name: 'salesrep',
operator: search.Operator.ANYOF,
values: '77'
})
Note also that for List/Record (select/dropdown) fields you should use the ANYOF operator rather than IS.
Further comments: if by "nested object keys" you are referring to values that come from record joins, then you can use the `join` property of the `search.createFilter(options)` options parameter. For example, if you wanted to use the sales rep's name instead of internal id, you could do:
search.createFilter({
join: 'salesrep',
name: 'entityid',
operator: search.Operator.IS,
values: 'Tom Sawyer' //Put the sales rep's name here
})
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论