English
Fx.utils
About 1044 wordsAbout 3 min
2026-01-09
1. htmlParseText extracts plain text from HTML
Extract plain text from HTML
Fx.utils.htmlParseText(<String html>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| html | String | Extract HTML content | Y |
Code examples
def ret = Fx.utils.htmlParseText('<div class="drop-content-item"><div class="drop-box"><div class="drop-box-item drop-box-item2"style="border: none"> <img class="img-icon"style="width:20px;"src="https://www.fxiaoke.com/ap/wp-content/uploads/2020/05/icon-live.png"><ahref="/ap/live/">Live Videos</a></p>RM public courses, CRM usage tips, digital transformation strategies, and latest industry application practices in video format</div>').result()
//Live Videos
//RM public courses, CRM usage tips, digital transformation strategies, and latest industry application practices in video format
log.info(ret)2. toPinyin Convert Chinese characters to pinyin
Chinese to Pinyin Conversion
Fx.utils.toPinyin(<String chinese>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| chinese | String | Chinese characters | Y |
Code examples
def ret = Fx.utils.toPinyin("测试").result()
//ceshi
log.info(ret)3. listPartition Array Partitioning
Array Splitting
Fx.utils.listPartition(<List list>, <Integer size>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| list | List | The array to be split | Y |
| size | Integer | Length of each sub-array after splitting | Y |
Code examples
List original = [1,2,3,4,5,6,7,8,9]
//[[1,2,3],[4,5,6],[7,8,9]]
List partition = Fx.utils.listPartition(original,3)4. listUnique Array Deduplication
Array Deduplication
Fx.utils.listUnique(<List list>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| list | List | List requiring deduplication | Y |
Code examples
def list = [1,1,1,2,2,3,4,5]
def ret = Fx.utils.listUnique(list)
// [1, 2, 3, 4, 5]
log.info(ret)5. toUTF8Bytes Convert string to byte array
Convert string to byte array
Fx.utils.toUTF8Bytes(<String content>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| content | String | String value | Y |
Code examples
def bytes = Fx.utils.toUTF8Bytes("hello你好")
String content = Fx.utils.toUTF8String(bytes)
//hello你好
log.info(content)6. toUTF8String Convert byte data to string
Convert byte data to string
Fx.utils.toUTF8String(<byte[] bytes>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| bytes | byte[] | Byte array | Y |
Code examples
def bytes = Fx.utils.toUTF8Bytes("hello你好")
String content = Fx.utils.toUTF8String(bytes)
//hello你好
log.info(content)7. getLevenshteinDistance calculates the difference between strings
Calculate the differences between strings
Fx.utils.getLevenshteinDistance(<String left>, <String right>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| left | String | Comparison string 1 | Y |
| right | String | Comparison string 2 | Y |
Code examples
def aa = Fx.utils.getLevenshteinDistance("test1","test2") // 1
log.info(aa)
def bb = Fx.utils.getLevenshteinDistance("test1","tet") // 2
log.info(bb)
def cc = Fx.utils.getLevenshteinDistance("test1","stet1") // 2
log.info(cc)
def dd = Fx.utils.getLevenshteinDistance("test1","test1") // 0
log.info(dd)Notice
- This return value represents the Levenshtein distance between the two input strings, which is the minimum number of edit operations (insertion, deletion, or substitution of characters) required to transform one string into another.
- Specifically:
- A return value of 0 indicates that the two strings are identical.
- The larger the return value, the greater the difference between the two strings, meaning more edit operations are needed to convert one into the other.
- If an issue occurs, it may return -1, which typically indicates an error or an inability to determine the distance.
8. getRequestSource Get the request source of the terminal
Obtain the request source of the terminal
Fx.utils.getRequestSource()
Code examples
//Android Android
//iOS iOS
//DingTalk DingTalk
//WX WeChat
//CloudHub CloudHub
//FSBrowser FenXiang Client
//WEB Web
//FSBrowser FenXiang Client
//Returns empty string if query fails (e.g. after workflow). Currently only available when function is directly triggered from terminal (e.g. button click)
//Gets the execution source of the function and returns a string
String source = Fx.utils.getRequestSource()9. getDeviceType Get Device Type
Get Device Type
Fx.utils.getDeviceType()
Code examples
def deviceType = Fx.utils.getDeviceType()
if(deviceType == 'mobile'){
//Mobile scenario dosomething
log.info("Mobile dosomething")
} else {
//Non-mobile scenario dosomething
log.info("Non-mobile dosomething")
}10. daysInMonth returns the number of days in a specified year and month
Returns the number of days in the specified year and month
Fx.utils.daysInMonth(<Integer year>, <Integer month>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| year | Integer | Year | Y |
| month | Integer | Month | Y |
Code examples
Fx.utils.daysInMonth(2020, 2) // Returns 2911. isLeapYear Returns whether the specified year is a leap year
Returns whether the specified year is a leap year
Fx.utils.isLeapYear(<Integer year>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| year | Integer | Year | Y |
Code examples
Fx.utils.isLeapYear(2020) //Returns true12. encodeHex Convert byte array to hexadecimal string
Convert byte array to hexadecimal string
Fx.utils.encodeHex(<byte[] bytes>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| bytes | byte[] | Byte array | Y |
Code examples
def hex = Fx.utils.encodeHex('testtest'.getBytes())
log.info(hex)13. decodeHex Convert hexadecimal string to byte array
Convert hexadecimal string to byte array
Fx.utils.decodeHex(<String str>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| str | String | String type | Y |
Code examples
def hex = Fx.utils.encodeHex('testtest'.getBytes())
log.info(hex) //7465737474657374
def str = Fx.utils.toUTF8String(Fx.utils.decodeHex(hex))
log.info(str) //testtest14. dataConvert converts map value time type to timestamp
BigDecimal type to String
Convert time-related types in map values to timestamps
Convert BigDecimal types to String
Other types remain unchanged
Fx.utils.dataConvert(<Map data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | Map | Map object | Y |
Code examples
def map = [
"date": Date.now(),
"dateTime": DateTime.now(),
"time": Time.now(),
"bigDecimal": BigDecimal.of("123.456")
]
def ret = Fx.utils.dataConvert(map)
log.info(ret) // {date=1726761600000, dateTime=1726826030045, time=35630056, bigDecimal=123.456}15. amountToEnWords Convert numeric amount to English words in uppercase
Convert Numeric Amount to English Words in Uppercase
Fx.utils.amountToEnWords(<String currency>, <BigDecimal bigDecimal>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| currency | String | Currency type. Currently supported: USD (US Dollar), CNY (Chinese Yuan), EUR (Euro), HKD (Hong Kong Dollar) | Y |
| bigDecimal | BigDecimal | Amount value | Y |
Code examples
BigDecimal b = BigDecimal.of("1848.00") // Amount
// Currency types: USD-US Dollar, CNY-Chinese Yuan, EUR-Euro, HKD-Hong Kong Dollar
String currType = "CNY"
String en = Fx.utils.amountToEnWords(currType, b)
log.info(en)//SAY CNY ONE THOUSAND EIGHT HUNDRED AND FORTY EIGHT ONLY16. getLang Get the current CRM language
Get current CRM language
Fx.utils.getLang()
Code examples
def lang = Fx.utils.getLang()
//en: English, zh-CN: Simplified Chinese, zh-TW: Traditional Chinese
log.info(lang)