Document toolboxDocument toolbox

(2024.2) Import Conditional Logic

Summary

The Import Conditional Logic is similar to PHP code, except in how some of the variables are named and referenced, and the very limited white list of available functions. Whenever the button on the Conditional Logic form is pressed, a validator will run to check the logic for errors. If errors are detected, the form will not be saved. At any time, the User can press the Validate button, and it will run the check and report any existing errors.

Help Button

A button is displayed on the form where the User can enter Conditional Logic. When that button is pressed, a complete list of the PHP constructs and functions that are available will be displayed.

Allowed Functions

Array

explode , implode , is_array , in_array , array_diff , array_diff_keycount

JSON

json_decode , json_encode

Date/Time

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

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 Utility

PCR_Utility_Logger, getInstance, notice

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


Referencing a Value from the Import File

To reference a value from the Import File, square brackets surrounding numbers to specify the csv index (column) must be used, or the position and size, we use 0 based counting from the start of the line, the first column or first character position is actually 0. For example, with a delimited file, to reference the index (column) 5, [4] would be used. For a fixed-width file, to reference a string starting at character 10 and spanning 4 characters, [9,4] would be used. 

To assign a value to one of the index (column) being assigned by the Import, the name of the table and name of the index (column) surrounded by square brackets would be referenced. For example, for a Contact Import, the User may want to set the first name. The reference would be [CONTACTS.FIRST_NAME]. On the Conditional Logic form, there is a helper button to help build these references. Click in the Conditional Logic window to position the Caret, then use the Record Column drop-down to select which index (column) to be referenced, then press the  button. This will insert the correct reference into the Conditional Logic window. 

The Conditional Logic cannot read any values from the Database. It is limited to working only with one line at a time of the input file.

User Defined Variables

User Defined Variables may be used within Conditional Logic. However, if the User wants to use them in the Conditional Logic, they all MUST begin with: "$cl_".  This requirement is in place so that User Defined Variables do not conflict with internal system variables.

Date Formatting

If a User needs to assign a Date type field in the Conditional Logic, the format is assumed to be in one of these formats: m/d/y or d-m-y.

Conditional Logic Flags

Sometimes an Import process needs to behave in a non-standard way due to special circumstances. To control this behavior, a User can set flags in the Import Conditional Logic. Usually, the flags are boolean, but other types are supported.

Syntax to set the flag in the Conditional Logic:

[FLAGS.IGNORE] = true;

The following is a list of the Import Conditional Logic Flags that are available in all Import types:

[FLAGS.IGNORE] default false

If set to true, this line of the input file will be ignored (skipped) by the Import process. 

You can also set the ignore flag to a string, using an array syntax, like this:

<code block>
[FLAGS.IGNORE][] = "The reason for the ignore";
<end code block>

This will let the reason get counted in the Import Files report totals. This can be useful if your Conditional Logic has several different rules that can cause a record to be ignored. It will let you see totals of how many records are ignored for each reason.

[FLAGS.FILENAME]

This is a read only field that contains the filename of the Import File being imported.

[FLAGS.FILELINE]

This is a read only field that contains the line number from the Import File of the record currently being imported.

There are other flags available in specific Import types that are described in the specific Import wiki pages.

User Defined Fields

User Defined Fields (UDFs) are handled through the Conditional Logic tab. Any UDFs have to be included in Conditional Logic in order to Import them into PCR-360.

To assign a UDF value, the User must know the Identifier name for the UDF. This is the value in the first index (column) of the User Defined Fields grid.

For example, to assign the Rollover GLA Date from input index (column) 4 in the GLA import, the assignment would look like this:

[GLA.UDF_ROLLOVERGLA68] = [4];

Where GLA is the table with the UDF and ROLLOVERGLA68 is the UDF Identifier.

The Identifier and table associations are verified by the Conditional Logic validations. If an invalid Identifier is used in the Conditional Logic, the Validate button or Save button shows the error when clicked, and it will not able to Save until valid data is entered.

Examples


Set a Contact First Name conditionally to field 3 or 4, whichever is filled in.

if ([3] != '') { [CONTACTS.FIRST_NAME]; } elseif ([4] != '') { [CONTACTS.FIRST_NAME]; }



Ignore input lines if the name is Joe.

This is a special assignment that will cause this input line to not get processed.

Note: The above example assumes [CONTACTS.FIRST_NAME] had been assigned prior to that code.



Build and set email address. This will take the first letter of the first name, the last name, and append them together with other email address components. So John Smith will get an email address of 'jsmith@pcr.com'