Document toolboxDocument toolbox

.Syntax v2020.1

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

The Custom API and Custom Events can invoke the Write methods for API types by using the call function. This function allows passing data from the Custom API or Events to the API logic.  When invoking this from the Custom API this feature allows you to reformat the incoming API data - perform data validation and lookup and then handoff the properly formatted data to write data.  When invoked from a Custom Event it allows scheduled or triggers events to update this data.

array $this->call ( string $method, array $bind_params);
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.

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"];
}


Allowed Functions

Array

explode , implode , is_array , in_array , array_diff , array_diff_key , count

JSON

json_decode , json_encode

cURL

curl_init , curl_setopt , curl_exec , curl_errno , curl_error , curl_getinfo , curl_close , http_build_query

Date/Time

date , time , mktime , strtotime , DateTime , DateInterval , add , sub, diff, format , setTimestamp , setTime , setDate

Debug

error_log, debug

Debug Function
$this->debug();

Note: The debug command outputs to a cache which is then displayed in the Debug tab/grid for the Custom Logic you are debugging.

Logical

if , elseif , else , switch , case , default , break , for , foreach , as , while , do-while , return , new

Mathematical

round , trunc ,ceil , floor , rand , srand , pow , exp , abs , max , min , bindec , hexdec , octdec , base_convert

PCR-360 Data

call , query , listGetByCode , listFindValue , listFindCode

Call Function
// $apiFunction Examples: saveService, saveServiceDesk, saveContact, saveCable, saveGla, saveEquipment, etc.
$this->call(string $apiFunctionToCall, array $params)
Query Function
array $this->query ( string $sql, array $bind_parameters );
listGetByCode Function
mixed $this->listGetByCode ( string $list_type, mixed $list_code );
listFindValue Function
string $this->listGetByCode ( int $recid );
listFindCode Function
string $this->listGetByCode ( int $recid );

String

is_numeric strtolower , strtoupper , substr , stristr , strstr , stripos , strpos , strripos , strrpos , addslashes , chr , trim , ltrim , rtrim , str_replace , preg_match preg_replace , preg_split , str_pad , sprintf substr_replace , strlen

Additional Functions

Contact PCR if you find a function that is not allowed, but would like to use. 

Validation functions

setError

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.

setError Function
$this->setError ( string $message );

setWarning

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.

setWarning Function
$this->setWarning ( string $message );

Triggering Events

PCR_Event, trigger, attach, attachDb

In this example the GLA Replace Event is triggered with specific parameters. For detailed information on which Events can be triggered, and how to trigger those Events, please navigate to the Triggerable Events List page.

PCR_Event Functions
PCR_Event::attachDb("replace-gla", [
    "Application_Model_Gla_Gla" => "eventReplaceGla"
]);
PCR_Event::trigger("replace-gla", [
	"contact" => 12345,        // Contact RECID
    "users_recid" => 456,      // Users RECID
    "glaRecid" => [1111],      // Old GLA RECID
    "replaceGlaRecid" => 2222, // Replacement GLA RECID
    "setInactiveGla" => true,
    "comment" => "This is a comment",
]);

Help Desk Portal - Email: help@pcr.com - Phone: 616.259.9242