Fxiaoke Developer Manual Fxiaoke Developer Manual
  • APL Development Manual
  • PWC Development Manual
  • OpenAPI Documentation
APL Code Introduction
API Reference
Development Tools
Release Notes
  • 简体中文
  • English
APL Code Introduction
API Reference
Development Tools
Release Notes
  • 简体中文
  • English
  • Getting Started

  • APL Function Open Scenarios

  • APL Class Open Scenarios

    • Common Library

    • Electronic Signature

    • Authentication Provider

    • Available Business Types

    • Object Controller Plugin

    • Event Listener

    • Object Export Plugin

    • ERP Integration Platform

    • Field Service Type Function Validation

    • FMCG Order Business Plugin

    • Object Business Handler

      • 1.Overview
      • 2.Configuration Steps
      • 3.Groovy Code Examples
      • 4.FAQ
    • Online Documentation

    • Custom Model

    • Environment Deployment

Groovy Code Example

class ObjectHandlerImpl implements ObjectHandler {  
    @Override  
    Result handle(FunctionContext context, Map<String, Object> arg) {  
        Map handlerDescribe = arg.handlerDescribe as Map  
        //Interface type (Add: Create, Edit: Modify, Invalid: Invalidate)  
        String interfaceCode = handlerDescribe.interfaceCode as String  
        //Handler type (before: Before button execution, after: After button execution)  
        String handlerType = handlerDescribe.handlerType as String  

        //Create button  
        if ("Add" == interfaceCode) {  
            //Main object data  
            Map objectData = arg.objectData as Map  
            //Detail object data  
            Map<String, List<Map<String, Object>>> detailObjectData = objectData.detailObjectData as Map  
            if ("before" == handlerType) {  
                String name = objectData.name as String  
                //Return error message when validation fails  
                if (name != null) {  
                    return Result.builder().success(false).errorMessage("Name cannot be empty").build()  
                }  
                //Modify data based on conditions  
                if (name.startsWith("test-handler")) {  
                    //Modify main object data  
                    objectData.name = name + DateTime.now().toTimestamp()  
                    //Modify detail object data  
                    if (detailObjectData != null && !detailObjectData.isEmpty()) {  
                        detailObjectData.each { apiName, detailDataList ->  
                            detailDataList.each {  
                                Map detailData = it as Map  
                                detailData.name = ((String) detailData.name) + DateTime.now().toTimestamp()  
                            }  
                        }  
                    }  
                    //Return modified data  
                    Map<String, Object> result = [:]  
                    result.objectData = objectData  
                    result.detailObjectData = detailObjectData  
                    return Result.builder().result(result).build()  
                }  
                //Return empty data when validation succeeds  
                return Result.builder().build()  
            }  
            if ("after" == handlerType) {  
                //Logic after successful data saving  
            }  
        }  

        //Edit button  
        if ("Edit" == interfaceCode) {  
            //Main object data  
            Map objectData = arg.objectData as Map  
            //Detail object data  
            Map<String, List<Map<String, Object>>> detailObjectData = objectData.detailObjectData as Map  
            if ("before" == handlerType) {  
                //Validation logic  
            }  
            if ("after" == handlerType) {  
                //Whether approval flow was successfully triggered  
                boolean triggerApprovalFlowSuccess = arg.triggerApprovalFlowSuccess as boolean  
                //Approval flow trigger type (Create: New, Update: Modify, Invalid: Invalidate)  
                String approvalFlowTriggerType = arg.approvalFlowTriggerType as String  
                //Successfully triggered edit approval flow, return directly  
                if (triggerApprovalFlowSuccess && "Update" == approvalFlowTriggerType) {  
                    return Result.builder().build()  
                }  
                //Logic after successful data saving  
            }  
        }  

        return Result.builder().build()  
    }  

    //Debug entry method  
    Result debug(FunctionContext context, Map<String, Object> arg) {  
        return handle(context, arg);  
    }  
}  
2.Configuration Steps
4.FAQ

← 2.Configuration Steps 4.FAQ→

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式