在NetSuite SuiteScript 2.0搜索中,是否有一种方法可以按嵌套对象键进行筛选?

huangapple go评论71阅读模式
英文:

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 &#39;nested properties&#39; 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&#39;s.

E.g. you want to find all the cusomer records, which have their salesrep referred record&#39;s id as &#39;77&#39;.

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 &#39;joined&#39; record). You&#39;ll see that there is no &#39;id&#39; search filter, but instead there is &#39;internalid&#39;, 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: &#39;salesrep.id&#39;,
        operator: search.Operator.IS,
        values: &#39;77&#39;
    });


must be (**also please not the array literal** in the values property, I&#39;m not sure if a string, as in your original example will work)

    var f1 = search.createFilter({
        name: &#39;internalid&#39;,
        join: &#39;salesrep&#39;,
        operator: search.Operator.IS,
        values: [&#39;77&#39;]
    });

I&#39;m not sure if your code will work, since it&#39;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&#39;m not sure what you mean by &quot;nested object keys&quot;, but there is a simple solution for your example of filtering by &#39;salesrep.id&#39; - you simply specify it as &#39;salesrep&#39;.  

    search.createFilter({
        name: &#39;salesrep&#39;,
        operator: search.Operator.ANYOF,
        values: &#39;77&#39;
    })

Note also that for List/Record (select/dropdown) fields you should use the ANYOF operator rather than IS.

Further comments: if by &quot;nested object keys&quot; 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&#39;s name instead of internal id, you could do:

    search.createFilter({
        join: &#39;salesrep&#39;,
        name: &#39;entityid&#39;,
        operator: search.Operator.IS,
        values: &#39;Tom Sawyer&#39;  //Put the sales rep&#39;s name here
    })

</details>



huangapple
  • 本文由 发表于 2023年5月11日 04:43:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76222421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定