Versions Compared

Key

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

...

Code Block
languagephp
string $this->listGetByCode ( int $recid );string $this->listGetByCode ( int $recid );

PCR-360 Utility

arrayToCsv, createFile, sendSystemMessage, callCustomEvent

arrayToCsv Function
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
*/

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

createFile Function
Code Block
$bytesWritten = $this->createFile('MY-OUTBOUND-FILE.csv', $csvRows, '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
}

String

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

...

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",
]);

Calling Custom Events

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

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

Sending a System Message

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

...

  • 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

...

$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

...

$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

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

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

  3. If the location does not exist, it will be created

  4. Will call file_put_contents and check the result, if the result is false, an If an error occurs while writing the file, the error will be loggedThe file_put_contents result , and false will be returned

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