# manage-groovy > Write Groovy logic for OFBiz services and scripts. Use when creating/debugging Groovy services or implementing entity logic. - Author: toaditi - Repository: toaditi/ofbiz-dev-agent-skills - Version: 20260124175846 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/toaditi/ofbiz-dev-agent-skills - Web: https://mule.run/skillshub/@@toaditi/ofbiz-dev-agent-skills~manage-groovy:20260124175846 --- --- name: manage-groovy description: Write Groovy logic for OFBiz services and scripts. Use when creating/debugging Groovy services or implementing entity logic. --- # Skill: manage-groovy ## Goal Write Groovy logic for OFBiz services and scripts. ## Triggers **ALWAYS** read this skill when: - Creating a new Groovy service or script. - Debugging a Groovy service failure. - Implementing an entity-based service logic. ## Use when - **Data Preparation**: Preparing data for UI/API responses (filtering, formatting). - **Orchestration**: Simple sequencing of services where Java is overkill. - **Maintenance**: One-off scripts. ## Don't use when - Core, stable business invariants (use Java). - Simple validation/orchestration (use XML Actions). - Complex transactions requiring strict compile-time safety. ## Inputs required: - dctx: DispatchContext (if service) - context: Map (if service) OR global bindings (if script) optional: - parameters: Map ## Outputs - `Map` (via `ServiceUtil.returnSuccess`/`returnError`). ## Procedure 1. **READ SKILL `coding-standards`**: Adhere to comments and style rules. 2. Create `src/main/groovy/[Package]/[Name].groovy`. 2. Define method `def myService()`. 3. Retrieve tools: `delegator` (DB), `dispatcher` (Service), `userLogin`. 4. Validate inputs (return error early if invalid). 5. Perform logic (DB ops, service calls). 6. Return result: `return success([key: val])`. ## Guardrails - **Functions**: Define logic in named methods, not top-level script code. - **Use Streams**: Use `.collect`, `.findAll`, `.each` for collection manipulation. - **Context**: Use `context` to push data to the screen. - **Core Logic**: Keep complex invariants in Java; use Groovy for glue/adaptations/ui-prep. - **Nulls**: Handle dynamic typing risks; check for nulls explicitly. ## Failure handling - **Validation**: Check `parameters.field`; return `error("Msg")` immediately. - **Service Errors**: Check `ServiceUtil.isError(result)` after every service call. ## Minimal example Input: `createFeature` service Output: ```groovy def createFeature() { if (!parameters.name) return error("Name missing") // Use clear parameter passing GenericValue newVal = makeValue("Feature", parameters) newVal.create() return success([id: newVal.featureId]) } ```