NetSuite SuiteQL 内建函数

之前写过一篇文章介绍SutieQL Query Tool,今天继续挖掘一下SuiteQL的价值。

NetSuite SuiteQL Query Tool_netsuite好用吗_毛岩喆的博客-CSDN博客这是一个非常好的NetSuite数据查询工具,免费、强大!所以忍不住安利给大家。首先介绍一下背景,SuiteQL是伴随SuiteAnalytics而来的一个基础组件,为NetSuite开发人员提供了一个按照SQL语法进行数据查询的工具。但是SuiteQL只有API供开发者使用,对于终端用户来说没有一个可用的UI工具。哪里有坑,哪里就有填坑人。所以,有个用户就基于SuiteQL组件开发了一个Bundle,赋予了其一个UI便于终端用户使用。好了,闲言少叙,上硬菜!https://blog.csdn.net/remottshanghai/article/details/127032699SuiteQL中有几个内建函数(Built-In),可以帮助我们在编写SQL语句时更加的方便。并不详细的介绍可以参见在线帮助。

NetSuite Applications Suite - SuiteQL Supported Built-in Functionshttps://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/article_161950565221.html今朝我们用一个SQL语句来综合实践一下:

SELECT
	Transaction.TranID,
	Transaction.trandate,
	Transaction.postingPeriod,
	TransactionAccountingLine.Account,
	BUILTIN.DF( TransactionAccountingLine.Account ) AS func_df,
	TransactionAccountingLine.Debit,
	TransactionAccountingLine.Credit,
  	BUILTIN.CONSOLIDATE(TransactionAccountingLine.Credit, 'INCOME', 'DEFAULT', 'DEFAULT', 3, 263, 'DEFAULT') as func_consolidate,
	BUILTIN.CURRENCY(TransactionAccountingLine.Credit) as func_currency,
	BUILTIN.CURRENCY_CONVERT(TransactionAccountingLine.Credit, 1) as func_currency_convert,
	BUILTIN.DF( TransactionLine.Subsidiary ) AS Subsidiary,
	BUILTIN.HIERARCHY(TransactionLine.Subsidiary, 'DISPLAY_JOINED')	 AS func_hierarchy
FROM 
	Transaction
	INNER JOIN TransactionAccountingLine ON
		( TransactionAccountingLine.Transaction = Transaction.ID )
	LEFT OUTER JOIN TransactionLine ON
		( TransactionLine.Transaction = TransactionAccountingLine.Transaction )
		AND ( TransactionLine.LineSequenceNumber = TransactionAccountingLine.TransactionLine )
WHERE 
	--Transaction.trandate >= BUILTIN.RELATIVE_RANGES('TY', 'START')
	Transaction.postingPeriod  in BUILTIN.PERIOD('LFY', 'START', 'ALL', '>')  
	AND ( TransactionAccountingLine.Account IS NOT NULL )
ORDER BY
	Transaction.trandate

在这段语句中,我们涉及了如下几个函数:

  • BUILTIN.DF( TransactionAccountingLine.Account )
  • BUILTIN.CONSOLIDATE(TransactionAccountingLine.Credit, 'INCOME', 'DEFAULT', 'DEFAULT', 3, 263, 'DEFAULT')
  • BUILTIN.CURRENCY(TransactionAccountingLine.Credit) 
  • BUILTIN.CURRENCY_CONVERT(TransactionAccountingLine.Credit, 1)
  • BUILTIN.HIERARCHY(TransactionLine.Subsidiary, 'DISPLAY_JOINED')
  • BUILTIN.RELATIVE_RANGES('TY', 'START')
  • BUILTIN.PERIOD('LFY', 'START', 'ALL', '>')  

运行结果如下:

由于严重缺乏支持材料,还有两个函数,不清楚如何使用。

  • CF
  • NAMED_GROUP

有清楚的同学请跟帖分享一下,谢啦!

后记

在提了Support Case后,得到如下答复:

For BUILTIN.CF,  This function has only one parameter - UMD field where UMD means Unified Metadata. Intention of this function is to get CRITERIA version of field value. In some special cases, there is different SQL fragment defined for UMD field whether it is used as return value or criteria field. (e.g. UMD field which is used as simple join key on UMD level, but it is implemented by two or more keys in DB - composite key). This function will allow us to return criteria version as return value in case that we would like to filter data outside of DB (e.g. in JAVA code or on customer side).

Examples of SuiteQL queries for BUILTIN.CF:
    1. select transaction.status, BUILTIN.CF(transaction.status) from transaction

    2. /* does not return anything because "where transaction.status" and "select transaction.status" are different SQL expressions */
         select * from transaction where transaction.status IN (select transaction.status from transaction)

    3. /* returns everything because "where transaction.status" and "select BUILTIN.CF(transaction.status)" are same SQL expressions */
         select * from transaction where transaction.status IN (select BUILTIN.CF(transaction.status) from transaction)

For BUILTIN.NAMED_GROUP, we know only following:
parameters are: Builtin.Named_Group(record_name, group_name) where record_name is UMD name of record and group_name is name of group defined on that record. On each record there can be different set of group_names - so the question should be directed to owner of the specified record.

The function returns filter options for workgroups for some record types (filter by: My Location, My Subsidiary, My team, etc). Named groups (label: my) currently for records: 
    • Department
    • Class
    • Location
    • Subsidiary
    • Entity

Also, every key field targeting above records (such as Entity -> Location) should support filtering by the {Me} group.

Example of SuiteQL queries for BUILTIN.NAMED_GROUP:
    1. SELECT id FROM Transaction WHERE entity IN (BUILTIN.NAMED_GROUP('employee', 'me'))
    2. SELECT id FROM Transaction WHERE entity IN (BUILTIN.NAMED_GROUP('employee', 'me'), BUILTIN.NAMED_GROUP('employee', 'me'), 5, 6, 7, 8)

如果有任何关于NetSuite的问题,欢迎来谈。我的邮箱:[email protected]

猜你喜欢

转载自blog.csdn.net/remottshanghai/article/details/130672644