English
Groovy Code Examples
About 373 wordsAbout 1 min
2026-01-09
1. Return Type: QueryTemplate
QueryTemplate serves as the return result for association query conditions, offering higher efficiency.
Unless QueryTemplate's query method cannot meet requirements, it is recommended to use QueryTemplate as the return type. This approach has no upper limit on returned data and delivers high execution efficiency.
1.1 Function Template:
QueryTemplate template1 = QueryTemplate.AND(
["name":Operator.LIKE("测试")],
["field_g7Zeh__c":Operator.LTE("测试单行文本")]
)
QueryTemplate template2 = QueryTemplate.AND(
["owner":Operator.LIKE("1000")],
["record_type":Operator.EQ("default__c")]
)
// QueryTemplate OR conditions require separate activation. Contact sales to order the product: 【Object List Filter Supports OR Conditions】
QueryTemplate template3 = QueryTemplate.OR(template1,template2)
return template3
// Query condition support
// product_id is a lookup field. The query template supports filtering results where the name field of the lookup object meets certain conditions.
QueryTemplate template = QueryTemplate.AND(
["product_id.name":Operator.EQ("测试")]
)
return template2. Return Type: Collection (List)
Using List as the return type is not recommended. This method has an upper limit of 500 records and lower efficiency when querying and using IDs as return values.
2.1 Function Template:
// Define ID List
List objectIds = []
...
// Write function logic and add selectable data IDs to objectIds
objectIds.add()
// The final return result is List`<String>` containing IDs of qualified data
return objectIdsPractical Scenario: Restrict product selection range for quote line items by product category. Different business types of quote line items select products from different categories.
Template Example for the Above Scenario:
// Get field values from the current operation object instance
String product = context.data.field_wPnHu__c
// Query data based on conditions and business logic
def ret = Fx.object.find("LookupFieldTargetObjectApiName", [["field_1tG48__c":product]], 100, 0)
// Return directly if query fails
if( ret[0] ){
Fx.log.info("Query exception")
return []
}
// Define ID List
List objectIds = []
QueryResult result = ret[1] as QueryResult
// Iterate query results and add all IDs to objectIds
result.dataList.each{ item ->
Map map = item as Map
objectIds.add(map._id)
}
// Return objectIds
return objectIds3. Return Type: RangeRule
Specify default business types when selecting or creating lookup fields.
3.1 Function Template:
QueryTemplate template = QueryTemplate.AND(
["name":Operator.LIKE("测试")]
)
RangeRule rangeRule = RangeRule.builder()
.queryTemplate(template)
.recordType("record_cbxZ8__c") // Default business type for lookup field creation
.build()
return rangeRule