Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

explode , implode , is_array , in_array , array_diff , array_diff_keycount

JSON

json_decode , json_encode

...

Call Function
Code Block
languagephp
//*
$apiFunction ExamplesOptions: 
  saveService, saveServiceDesk, saveContact, saveCable, saveGla, saveEquipment, saveLocation,
  renderCustomReport, etc. renderCableViewPath
*/

array $this->call (string $apiFunctionToCall, array $params, bool $commitOnSuccess)

...

Code Block
languagephp
array $this->query ( string $sql, array $bind_parameters );

// Example:
$results = $this->query("SELECT * FROM SERVICES WHERE RECID = :recid", [':recid' => 123]);
listGetByCode Function
Code Block
languagephp
mixed $this->listGetByCode ( string $list_type, mixed $list_code );

...

arrayToCsv Function
Code Block
arrayToCsv(array $data, string $delimiter = ',', string $enclosure = '"'): array 

$data: An array of values to convert to CSV

$delimiter: The character that is used to separate the values

$enclosure: Character used to encapsulate the data when the data contains the delimiter

Code Block
/*
Generate a CSV in the OUTBOUND directory 
named 'MY-OUTBOUND-FILE.csv' with the following content:

      a, b, c, 1, 2, 3
      d, e, f, 4, 5, 6
*/

$array = [
  ['a', 'b', 'c', 1, 2, 3],
  ['d', 'e', 'f', 4, 5, 6]
];
$csv = $this->arrayToCsv($array);
createFile Function

Users can use Custom Logic to create files directly onto the Inbound/Outbound directories for processing either by internal processes (Inbound) or external processes (Outbound).

Code Block
createFile(string $filename, string|array $content, string $location = 'OUTBOUND', bool $overwrite = false) : int|false

$filename: The name of the file to create. Any path will be ignored; just the basename used

$content: The data to write to the file. String will be written as is, arrays will be written as if implode('', $content)

$location: The location in which to create the file. Supported values are INBOUND and OUTBOUND; any other value should cause the function to return false after logging an error

  • If the location is not supported, it will log an error and return false

  • If the overwrite is false and the file exists, it will log an error and return a false

  • If the location does not exist, it will be created

  • If an error occurs while writing the file, the error will be logged, and false will be returned

  • When the file is successfully written, the number of bytes written will be returned

Code Block
// Example
$bytesWritten = $this->createFile('MY-OUTBOUND-FILE.csv', $csv , 'OUTBOUND', true);

if ($bytesWritten === false) {
  // There was an error creating the file, handle that here
  // Check the error log for more details
} else {
  // The file was created successfully $bytesWritten will be the number of bytes written
}

...

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

Validation functions

These functions are specific to Custom Validation

setError Function

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.

...

Code Block
languagephp
$this->setError ( string $message );

setWarning Function

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.

...

Code Block
languagephp
$this->setWarning ( string $message );

...

Code Block
languagephp
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",
]);
PCR_Event::detachDb("replace-gla");

Calling Custom Events

The following function in the Custom Logic tab allows the User to call a Custom Event. This enables flexibility in having a single custom process gather data for different pieces of Custom Logic.

Code Block
mixed $this->callCustomEvent (string $eventIdentifier, array $data); 

// Example:
$callEventResult = $this->callCustomEvent('Event Identifier', $data ?? []);
if ($callEventResult > 10) {
  // Do something for 10 or more
} else {
  // Do something for 9 or less
}

...

A system message can be sent from Custom Logic using the following format:

Code Block
languagephp
bool $this->sendSystemMessage(string $subject, string $body, int $contactRecid, string $identifier);

//Example:
$contactRecid = %YOUR-CONTACTS-RECID%123;
$response = $this->sendSystemMessage(
	// Subject
    'Test Message',
	// Body
    'This is a System Message generated from custom logic',
	// The RECID of the contact the message will be sent to
    $contactRecid,
	// TheA desciptive identifier that will be included inat the
	// end of the message header ("{$customerName} System Message\n({$logicIdentifier$identifier})\n\n";)
	%THE-CUSTOM-IDENTIFIER%$identifier
);
return true;
  • For Custom Events “THE-CUSTOM-IDENTIFIER“ is available from $data['custom_identifier'].

  • For the Custom API, “THE-CUSTOM-IDENTIFIER“ is available from $apiLogic['IDENTIFIER'].

  • For Custom Validation, “THE-CUSTOM-IDENTIFIER“ is not found in any of the variables, so we just need to make it match our Description of the Validation.

  • For Custom Reports, “THE-CUSTOM-IDENTIFIER“ is available from $params['identifier'].

Create a File on the Inbound/Outbound Directory using Custom Logic

Users can use Custom Logic to create files directly onto the Inbound/Outbound directories for processing either by internal processes (Inbound) or external processes (Outbound).

  • Example: arrayToCsv(array $data, string $delimiter=',', string $enclosure='"'): array

$data: An array of values to convert to a single line for a CSV

$delimiter: The character that is used to separate the values

$enclosure: Character used to encapsulate the data when the data contains the delimiter

  • Example: createFile(string $filename, string|array $content, string $location='OUTBOUND', bool $overwrite=false) : int|false

...

;

...

$content: The data to write to the file. String will be written as is, arrays will be written as if implode('', $content)

$location: The location in which to create the file. Supported values are INBOUND and OUTBOUND; any other value should cause the function to return false after logging an error

...

If the location is not supported, it will log an error and return false

...

If the overwrite is false and the file exists, it will log an error and return a false

...

If the location does not exist, it will be created

...

If an error occurs while writing the file, the error will be logged, and false will be returned

...