The "utils" option allows you to define custom global utility functions. One use of a custom utility function is for populating a dropdown from the database. For example, you may wish to have a custom field on a contract that tracks what product is associated to it. There are two main steps to do this; define the custom function and then tell the custom field to pull from the function.

Using the module manifest organization mentioned in a previous post (https://www.sugaroutfitters.com/blog/organizing-files-in-a-module-zip) we first create the utils function in contract_products.php:
/extensions/application/utils/contract_products_utils.php

// /extensions/application/utils/contract_products_utils.php
function getProducts(){
static $products = null;
if(!$products){
global $db;
$query = "SELECT id, name FROM products where deleted = 0 order by name asc ";
$result = $db->query($query, false);
$products = array();
$products[''] = '';
while (($row = $db->fetchByAssoc($result)) != null) {
$products[$row['id']] = $row['name'];
}
}
return $products;
}

Now we tell our custom field to pull from this new function:
/extensions/modules/Contracts/vardefs/product_dropdown_vardefs.php

// /extensions/modules/Contracts/vardefs/product_dropdown_vardefs.php
$dictionary['Contract']['fields']['product_c'] = array (
'name' => 'product_c',
'vname' => 'LBL_PRODUCT',
'function' => 'getProducts',
'type' => 'enum',
'len' => '100',
);

Finally, we add these to the manifest so that it will get installed via the Module Installer:

//manifest.php
//...............
'vardefs' =>
array (
//copies to custom/Extension/modules/Contracts/Ext/Vardefs
array (
'from' => '<basepath>/extensions/modules/Contracts/vardefs/product_dropdown_vardefs.php',
'to_module' => 'Contracts',
),
),
'utils' =>
array (
//copies to custom/Extension/application/Ext/Utils/
array (
'from' => '<basepath>/extensions/application/utils/contract_products_utils.php',
),
),
//..........
view raw manifest.php hosted with ❤ by GitHub

What other purposes have you used custom utils for?