Each of the different types of Custom Logic: Custom Events, Custom API, and Custom Validation share these common syntaxes and available functions.
PCR-360 Data functions
query
Execute read-only SQL query on database.
array $this->query ( string $sql, array $bind_parameters );
Parameters
$sql The query string. All data inside the query should be bound with named bind variables or properly escaped.
$bind_parameters An array of key value pairs with elements that are bound parameters in the SQL statement being executed. Array key names match the named bind variables in the SQL statement.
Return Values
Returns FALSE on failure. For successful queries, query() will return an array of data.
listGetByCode
Lookup the RECID(s) for the List determined by the type and the code(s).
mixed $this->listGetByCode ( string $list_type, mixed $list_code );
Parameters
$list_type The List Type specification of the desired record.
$list_code A string or array specifying the one or more List Codes belonging to the specified List Type. Only RECIDs for valid Codes will be returned. An array of three codes where one is invalid will return an array of two valid RECIDs.
Return Values
Returns a List RECID or array of List RECIDs if records were found. Returns NULL if nothing is found.
listFindValue
Lookup the List value for given List RECID.
string $this->listGetByCode ( int $recid );
Parameters
$recid The List Recid to find in the LISTS table.
Return Values
List Value of the specified record. Returns NULL if nothing is found.
listFindCode
Lookup the List code for given List RECID.
string $this->listGetByCode ( int $recid );
Parameters
$recid The List Recid to find in the LISTS table.
Return Values
List Code of the specified record. Returns NULL if nothing is found.
call
Custom Logic can invoke the API endpoints by using the call function. This function allows passing data from the logic to the API endpoint. When invoking this from the Custom API this feature call functions will follow the same API permissions granted the API Key that is being used.
/* $apiFunction Options: saveService, saveServiceDesk, saveContact, saveCable, saveGla, saveEquipment, saveLocation, renderCustomReport, renderCableViewPath */ array $this->call (string $method, array $params, bool $commitOnSuccess)
Parameters
$method The callable method name. The available callable methods: saveCable, saveContact, saveEquipment, saveGla, saveService, and saveServiceDesk
$params An array of key payload data that is passed to the other API calling function.
$commitOnSuccess A True/False value telling PCR-360 whether to commit the database transaction successful call or not. When True, if a call is successful, PCR-360 will commit the change. When not provided with a True, the function will assume False is desired, and if an error occurs down the line, any successful changes will be rolled back. This parameter is ignored for Custom Validations.
Return Values
The function returns a result array containing 'data' which specifies the outcome of the call. For a successful call to saveServiceDesk, this array contain the Service Desk item/action that was created.
Example
In this example, the $payload array contains all the parameters required to create a Service Order and Action
$result = $this->call("saveServiceDesk", $payload); $response["servicedesk_number"] = $result["data"];
Example
In this example, the Contact API is being invoked via the Custom API endpoint
$contact_request = [ "customer_number" => "ABC123", "last_name" => "Help", "first_name" => "PCR", "email" => "help@pcr.com", "email_directory" => 1, "phone_number" => "616-555-1212", "phone_primary" => 1, "phone_type" => 1234, // RECID from Lists "phone_directory" => 1, "status" => 1, "contact_directory" => 1, "contact_types" => "CUSTOMER", ]; $result_contact = $this->call("saveContact", $contact_request); if($result_contact["status"] == "success") { $response["contact"] = $result_contact["data"]; }
debug
The debug command outputs to a cache which is then displayed in the Debug tab/grid for the Custom Logic you are debugging.
Example
In this example, the debug function is being invoked.
Example debug use
$this->debug();
- 1 Allowed Functions
- 1.1 Array
- 1.2 Class/Object
- 1.3 Class/Interface Access
- 1.4 JSON
- 1.5 cURL
- 1.6 Date/Time
- 1.7 Exception Handling
- 1.8 Logical
- 1.9 Mathematical
- 1.10 PCR-360 Data
- 1.11 PCR-360 Debug
- 1.12 PCR-360 Events
- 1.13 PCR-360 Reports
- 1.14 PCR-360 Utility
- 1.15 PCR-360 Validation
- 1.16 Regular Expressions (Perl-Compatible)
- 1.17 String
- 1.18 URLs
- 1.19 Variable Handling
- 1.20 Additional Functions
For reference on all non-PCR-360 Functions, please refer to the PHP Documentation.
Allowed Functions
Array
array_column, array_chunk, array_combine, array_count_values, array_diff, array_diff_assoc, array_diff_key, array_fill, array_fill_keys, array_flip, array_intersect, array_intersect_assoc, array_intersect_key, array_intersect, array_is_list, array_key_exists, array_keys, array_merge, array_merge_recursive, array_multisort, array_pad, array_pop, array_product, array_push, array_rand, array_reduce, array_replace, array_replace_recursive, array_reverse, array_search, array_shift, array_slice, array_splice, array_sum, array_unique, array_unshift, array_values, compact, count, current, end, extract, in_array, key_exists, krsort, ksort, list, next, pos, prev, range, reset, rsort, shuffle, sort
Class/Object
get_called_class, get_class, is_a, is_subclass_of
Class/Interface Access
DateInterval, DateTime, Exception, PCR_Event, PCR_Exception, throwable
JSON
json_decode, json_encode, json_last_error, json_last_error_msg, json_validate
cURL
curl_close, curl_copy_handle, curl_errno, curl_error, curl_escape, curl_exec, curl_getinfo, curl_init, curl_pause, curl_reset, curl_setopt, curl_setopt_array, curl_strerror, curl_unescape
Date/Time
add, diff, date_add, date_create, date_create_from_format, date_diff, date_format, date_get_last_errors, date_interval_create_from_string, date_interval_format, date_parse, date_parse_from_format, date_sub, date_time_set, date_timestamp_get, date_timestamp_set, date_timezone_get, date_timezone_set, date, format, mktime, microtime, setDate, setTime, setTimestamp, strtotime, sub, time
Exception Handling
getPrevious, getCode, getLine
Logical
as, if, break, case, catch, continue, default, do, else, elseif, finally, for, foreach, function, match, new, return, switch, try, while
Mathematical
abs, base_convert, bindec, ceil, exp, floor, hexdec, max, min, octdec, pow, rand, round, srand, trunc
PCR-360 Data
call, listFindCode, listFindValue, listGetByCode, query
call Function: Calling API Logic
array $this->call(string $apiFunctionToCall, array $params, bool $commitOnSuccess);
query Function: Querying Data
array $this->query(string $sql, array $bind_parameters);
listGetByCode Function: Retrieving List Values
mixed $this->listGetByCode(string $list_type, mixed $list_code);
listFindValue Function: Retrieving List Values
string $this->listFindValue(int $recid);
listFindCode Function: Retrieving List Values
string $this->listFindCode(int $recid);
PCR-360 Debug
debug, error_log
debug Function: Debugging Custom Logic
$this->debug(mixed $debug);
PCR-360 Events
attach, attachDb, callCustomEvent, detach, detachDb, trigger
PCR-360 Reports
addError, assign, barcode, loadReport
PCR-360 Utility
arrayToCsv, createFile, sendSystemMessage
arrayToCsv Function: Building CSV Data
string $this->arrayToCsv(array $data, string $delimiter = ',', string $enclosure = '"')
createFile Function: Creating Inbound/Outbound Files
int|false $this->createFile(string $filename, string|array $content, string $location = 'OUTBOUND', bool $overwrite = false);
sendSystemMessage Function: Sending a System Message
bool $this->sendSystemMessage(string $subject, string $body, int $contactRecid, string $identifier);
PCR-360 Validation
setError, setMessage, setWarning
setError Function: Errors and Warning in Validation
Sets a validation error message. This messages output in the UI if the validation logic returns false. If this function is called multiple times, only the message from the last calls is displayed.
$this->setError(string $message);
setWarning Function: Errors and Warning in Validation
Sets the validation warning message. This messages output in the UI only if the logic does not return false. If this function is called multiple times, only the message from the last calls is displayed.
$this->setWarning(string $message);
Regular Expressions (Perl-Compatible)
preg_filter, preg_grep, preg_last_error, preg_match, preg_match_all, preg_quote, preg_replace, preg_split
String
addslashes, bin2hex, chr, explode, html_entity_decode, htmlentities, htmlspecialchars, htmlspecialchars_decode, implode, ltrim, nl2br, number_format, rtrim, sprintf, str_contains, str_ends_with, str_getcsv, str_ireplace, str_pad, str_repeat, str_replace, str_shuffle, str_split, str_starts_with, strcasecmp, strip_tags, stripslashes, strtolower, strtoupper, substr_compare, substr_count, substr_replace, substr, stristr, strlen, stripos, strpos, strripos, strrpos, strstr, trim, wordwrap
URLs
base64_decode, base64_encode, get_headers, http_build_query, parse_url, rawurldecode, rawurlencode, urldecode, urlencode
Variable Handling
gettype, is_array, is_bool, is_float, is_int, is_iterable, is_numeric, is_object, is_string, isset
Additional Functions
Contact PCR if you find a function that is not allowed, but would like to use.