Network expression rules
NEX tester
Network expression (NEX) rules can now be tested before they are used to populate or transform data.
This feature is enabled by default in your Network instance.
Testing NEX rules
Use the NEX Tester to ensure the rule works before it is applied to the data.
To test Network expressions:
-
In the Admin console, click System Interfaces > NEX Tester.
-
Copy or write your NEX rule in the box.
Tip: Comments are now supported in NEX rules, for example, /*This is a comment*/ or //end of line. Include comments to add meaningful information for other users.
The expression validates as you write the rule. If an error is found, hover over the error icon to see the details.
-
Click Format and Validate to format the expression.
Syntax highlighting
The syntax is highlighted with different colors so you can easily find the different elements of the expression.
Element Color Examples Keywords Blue IF, BOOLEAN, LONG Functions Blue contains, uppercase, now Field names Pink address__v, is_veeva_master__v Comments Light Grey //end of line Format
-
Pairs - Hover over a bracket (() to highlight the other bracket in the pair so you can easily see enclosed parameters.
-
Carets - Carets display beside lines that can be collapsed or folded. Click the caret to collapse the expression so you can easily see the statement.
-
-
In the Test NEX section, add a Veeva ID (VID) to see a sample result from the NEX rule. The VID must be a valid VID in your Network instance.
Lookup functions are also supported so you can test the NEX rule using a lookup table.
After you add a VID, it will be remembered the next time you test a NEX rule so you don't have to enter it again.
-
Click Evaluate Formula.
The Result section displays the Value that will display in the field and the fields and values that were used in the rule.
The values display if you have access to the data through your data visibility profile. If you do not have access, you can see that the rule works, but not the actual values.
Example
-
Click Copy to Clipboard and paste the expression in the feature where it will be used; for example, paste it in a source subscription configuration.
Supported features
The NEX Tester feature can be used to test expressions for any feature that supports NEX rules.
NEX rules can also be tested and formatted in the following configurations:
-
data model fields
-
OpenData country subscription (for filtering parent HCOs)
-
transformation rules
NEX rules cannot be tested in source subscription configurations. Test the rule in the NEX Tester feature and copy it to the source subscription.
Example - data model fields
The NEX rule that will be used to populate this field value can be tested directly in the field configuration.
New syntax
NEX rules now support SELECT statements.
Using this function enables you to retrieve data from sub-objects and relationship objects to populate entity level fields. For example, you can pull DEA numbers from the License sub-object to populate a field on HCP records. You can then map the fields to Veeva CRM or any other downstream systems.
The SELECT statement and supported functions can replace the need to use custom scripts in combination with NEX rules.
This enhancement is enabled by default in your Network instance.
Supported features
The SELECT statement, in combination with the ALL, ANY, DISTINCT, and FIRST functions, can be used anywhere in Network where NEX rules are supported.
For example, use in NEX rules in the following features:
-
source subscriptions (Transformation and After Update rule points)
-
data model fields
-
transformation rules
-
OpenData subscriptions (filtering records)
Source subscription considerations
When NEX expressions are used in source subscriptions, line breaks are not supported. The NEX expression must be one line.
Example 1
A NEX rule on an HCP custom field. The rule looks through the addresses on the HCP record and populates the field with the first primary address that meets the following criteria:
-
address_status__v
value is A (Active) -
record_state__v
value is VALID or UNDER_REVIEW -
address_ordinal__v
is 1If multiple addresses have an ordinal of 1, use the most recently modified address
If multiple addresses match all conditions above, the Veeva ID (VID) is used as the tiebreaker.
NEX rule
The rule uses the SELECT statement with the FIRST function.
SELECT FIRST (addr.vid__v FROM addresses__v AS addr WHERE addr.address_primary__c == 'Y' OR (addr.address_ordinal__v == 1 AND addr.address_status__v == 'A' AND (addr.record_state__v IN [ 'VALID', 'UNDER_REVIEW' ])) ORDER BY addr.modified_date__v, vid__v DESC)
NEX rule for source subscriptions
Use this syntax if you are using the rule in a source subscription.
[ "custom_field__c = SELECT FIRST (addr.vid__v FROM addresses__v AS addr WHERE addr.address_primary__c == 'Y' OR (addr.address_ordinal__v == 1 AND addr.address_status__v == 'A' AND (addr.record_state__v IN [ 'VALID', 'UNDER_REVIEW' ])) ORDER BY addr.modified_date__v, vid__v DESC)" ]
Result
The HCP field is populated with the address VID.
Example 2
A NEX rule on an HCP custom field that uses a lookup table to populate the field.
Description
In this example, the rule accesses the lookup table called citytier_t.csv. It will return the first value from the locality_v
field that meets the following criteria:
-
record_state__v
value is VALID or UNDER_REVIEW -
vid__v
is not null
Note: If multiple addresses match all the conditions above, the VID is used as the tiebreaker.
NEX rule
Use the SELECT statement with the FIRST function to return a value from a lookup table and update a custom field.
LOOKUP('citytier__t', 'city_tier_cn__c', locality__v: SELECT FIRST (addr.city_tier_cn__c FROM addresses__v AS addr WHERE addr.record_state__v IN ['VALID', 'UNDER_REVIEW'] AND addr.vid__v != null ORDER BY addr.vid__v)) ?? '1'
NEX rule for source subscriptions
Use this syntax if you are using the rule in a source subscription.
[ "custom_field__c = LOOKUP('citytier__t', 'city_tier_cn__c', locality__v: SELECT FIRST (addr.city_tier_cn__c FROM addresses__v AS addr WHERE addr.record_state__v IN ['VALID', 'UNDER_REVIEW'] AND addr.vid__v != null ORDER BY addr.vid__v)) ?? '1'" ]
Result
The HCP custom, city_tier_cnc__c
, field is populated with the appropriate tier from the first city in the lookup table that met the address criteria.
Example 3
A NEX rule on an HCP custom field that populates the field with a separated list of specific values.
Description
In this example, the rule looks through the licenses for specific states on the record. It populates the field with a concatenated list of those states if the license has the following criteria:
-
license_status__v
value is A (Active) -
record_state__v
value is VALID -
type__v
value is state (case insensitive)
Other requirements:
-
preserve the order that is presented in the state collection
-
if the HCP does not have a license in the state collection, return NULL
NEX rule
This rule uses SELECT with the DISTINCT function.
(SELECT DISTINCT (lic.type_value__v FROM licenses__v AS lic WHERE lic.license_status__v == 'A' AND UPPERCASE(lic.record_state__v) == 'VALID' AND UPPERCASE(lic.type__v) == 'STATE' AND (lic.type_value__v IN ['CA', 'CO', 'WA', 'DEA', 'NY']) ORDER BY lic.type_value__v) AS result, IF(ISEMPTY(result), null, JOIN(result, ';')))
NEX rule for source subscriptions
Use this syntax if you are using the rule in a source subscription.
[ "custom_field__c = (SELECT DISTINCT (lic.type_value__v FROM licenses__v AS lic WHERE lic.license_status__v == 'A' AND UPPERCASE(lic.record_state__v) == 'VALID' AND UPPERCASE(lic.type__v) == 'STATE' AND (lic.type_value__v IN ['CA', 'CO', 'WA', 'DEA', 'NY']) ORDER BY lic.type_value__v) AS result, IF(ISEMPTY(result), null, JOIN(result, ';')))" ]
Result
The field is populated with a concatenated list of states from the type_value__v
field separated by a semi-colon. If none of the licenses meet the criteria, null is returned.
Example results
The HCP record contains the following licenses.
The custom field is populated with the specific states that met the criteria defined in the NEX rule.
Note: Previously, this could be done only by using NEX rules in combination with a custom script.
Example 4
A NEX rule on an HCP custom field that looks through the licenses on the record and populates the field with the collection of license values.
Description
Populate a field with all active state licenses on the HCP record.
The licenses must have the following criteria:
-
type_value__v
is not empty -
license_number__v
is not empty -
type__v
value is state (case insensitive) -
license_status__v
value is A (Active) -
record_state__v
value is VALID or UNDER_REVIEW
Other requirements
-
populate each license as <
type_value_v
> - <license_number_v
> -
sort the collection
-
separate each value with a semi-colon (;)
-
add a trailing separator ';' if the field value is not empty
-
return empty string if licenses don't exist or are empty
NEX rule
This rule uses SELECT but does not define a function. If a function isn't defined , ALL is assumed.
(JOIN(STRINGSORT(SELECT (CONCAT(lic.type_value__v, ' - ', lic.license_number__v) FROM licenses__v AS lic WHERE !ISEMPTY(lic.type_value__v) AND !ISEMPTY(lic.license_number__v) AND UPPERCASE(lic.license_status__v) == 'A' AND (UPPERCASE(lic.record_state__v) IN ['VALID', 'UNDER_REVIEW']))), ';') AS result, IF(!ISEMPTY(result), CONCAT(result, ';'), result))
NEX rule for source subscriptions
Use this syntax if you are using the rule in a source subscription.
[ "custom_field__c = (JOIN(STRINGSORT(SELECT (CONCAT(lic.type_value__v, ' - ', lic.license_number__v) FROM licenses__v AS lic WHERE !ISEMPTY(lic.type_value__v) AND !ISEMPTY(lic.license_number__v) AND UPPERCASE(lic.license_status__v) == 'A' AND (UPPERCASE(lic.record_state__v) IN ['VALID', 'UNDER_REVIEW']))), ';') AS result, IF(!ISEMPTY(result), CONCAT(result, ';'), result))" ]
Result
The custom field is populated with a concatenated list of values, <type_value__v
> - <license_number__v
>, separated by semicolon. If none of the licenses meet the criteria, null is returned.
Example results
The HCP record contains the following licenses.
The custom field is populated with the list of license values that meet the criteria defined in the NEX rule.
Note: Previously, this could be done only by using NEX rules in combination with a custom script.