What is a context CTX['.']?
Go back to Schemas configuration guide
When we are working with any type of precessor, there are times we need to refer to other data points within the schema or from a different schema. We will walk through an example to clarify these concepts.
Schema context guide CTX[]
The Data point value can be accessed using CTX in configuration. Each value in the current data block/entry can be accessed and modified. To access the value of a specificdataPoint, simply provide the name of the dataPoint as a key within square brackets. For example:
CTX['name'] To access the value of the current dataPoint, provide a period character instead, like below:
CTX['.']
Here is an example of how to access a value from CTX:
1 2 3 4 5 6 7 8 9 10 |
|
Here is an example of how to set a value in CTX:
1 2 3 4 5 6 7 8 9 10 |
|
Schema context examples
-
We are going to use the schemas shown below to explain the relevant consepts.
CUSTOMER SCHEMA (Cross schema)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<schema name="CUSTOMER"> <identityKeys> <identityKey>CUSTOMER_ID</identityKey> </identityKeys> <dataPoint name="CUSTOMER_ID" dataType="STRING"> <nullable>false</nullable> </dataPoint> <dataPoint name="FIRST_NAME" dataType="STRING" /> <dataPoint name="LAST_NAME" dataType="STRING" /> <dataPoint name="COMPANY_NAME" dataType="STRING" /> <dataPoint name="ISIN_CUST" dataType="STRING" /> <dataPoint name="COMPANY_NAME" dataType="STRING" /> </schema>
COMPANY SCHEMA (Current schema)
1 2 3 4 5 6 7 8 9 10 11 12
<schema name="COMPANY"> <identityKeys> <identityKey>ISIN</identityKey> </identityKeys> <dataPoint name="ISIN" dataType="STRING"> <nullable>false</nullable> </dataPoint> <dataPoint name="COMPANY_ID" dataType="STRING" /> <dataPoint name="NAME" dataType="STRING" /> </schema>
-
CTX reference [Current Schema]
- See the comments within the code below for clarification.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<schema name="CUSTOMER"> <dataPoint name="ISIN_CUST" dataType="STRING"> <consDPProcessor name="MY_CONS_PROCESSOR_NAME" entity="GEN_EXPRESS"> <config> <![CDATA[ // CTX['.'] **CTX['.'] refers to CUSTOMER.ISIN_CUST data point // CTX['COMPANY_NAME'] refers to CUSTOMER.COMPANY_NAME ]]> </config> </consDPProcessors> </dataPoint> <dataPoint name="FIRST_NAME" dataType="STRING" /> <dataPoint name="LAST_NAME" dataType="STRING" /> </schema>
-
CTX reference [Cross Schema]
- If we need to refer to a data point value from another schema (Cross schema data point), it is slighly more complicated because we need to make sure the two data blocks from two different schemas match.
- The Consolidated Data Point Processor,
GEN_EXPRESS <consDPProcessor name="MY_CONS_PROCESSOR_NAME">
shown in the configuratiionbelow achieves the following: - It checks if there is a matching COMPANY record in both tables using
CUSTOMER.ISIN_CUST
andCOMPANY.ISIN_VERIFIED
. -
If there is a match it overrides the value of
CUSTOMER.COMPANY_NAME
with the valueCOMPANY_NAME
. -
Note: Please refer to our Roadmap for details of the next version of the standardised script interface which will improve the current syntax and enhance the out of the box script functionality.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<schema name="CUSTOMER"> <dataPoint name="COMPANY_NAME" dataType="STRING"> <consDPProcessor name="MY_CONS_PROCESSOR_NAME" entity="GEN_EXPRESS"> <config> <![CDATA[ // Find a company match using // CUSTOMER.ISIN_CUST == COMPANY.ISIN var fetchedValue = CTX.DDX( 'COMPANY' , ['ISIN_CUST' : CTX['ISIN'] ], 'NAME') // If you find a match, then override // the current data point value [CUSTOMER.COMPANY_NAME] with // the cross schema value [COMPANY.NAME] if(fetchedValue != null) CTX['COMPANY_NAME'] = fetchedValue // or CTX['.'] = fetchedValue else // If you do not find a match, then append // '_INVALID' to the // the current data point value [CUSTOMER.COMPANY_NAME] CTX['.'] = CTX['.'].concat("_").concat("INVALID") ]]> </config> </consDPProcessors> </dataPoint> <dataPoint name="FIRST_NAME" dataType="STRING" /> <dataPoint name="LAST_NAME" dataType="STRING" /> </schema>
-
CTX Cross data point value update [Current Schema]
- Before continuing with this exmaple you need to thoroughly understand the concepts described above in this page.
- Notice below that the following modifications have been made.
- We are now fetching the
ISIN
instead ofNAME
from theCOMPANY
schema. CTX.DDX( 'COMPANY' , ['ISIN_CUST' : CTX['ISIN'] ], 'ISIN')
- We are updated the value of the data point
ISIN_CUST
and not - The value of the data point
COMPANY_NAME
. - Note: The
audit
will still register the processorMY_CONS_PROCESSOR_NAME
that changed theISIN_CUST
value. - Note: Although this is possible, this approach is NOT recommended, because as your solution grows it will be hard to identify all the places a specific data point value is modified.
-
Note: The recommended approach is to define another processor within the definition of
<dataPoint name="ISIN_CUST" dataType="STRING"\>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<schema name="CUSTOMER"> <dataPoint name="COMPANY_NAME" dataType="STRING"> <consDPProcessor name="MY_CONS_PROCESSOR_NAME" entity="GEN_EXPRESS"> <config> <![CDATA[ // Find a company match using // CUSTOMER.ISIN_CUST == COMPANY.ISIN var fetchedValue = CTX.DDX( 'COMPANY' , ['ISIN_CUST' : CTX['ISIN'] ], 'ISIN') // If you find a match, then override // the current data point value [CUSTOMER.COMPANY_NAME] with // the cross schema value [COMPANY.ISIN] if(fetchedValue != null) CTX['ISIN_CUST'] = fetchedValue else // If you do not find a match, then append // '_INVALID' to the // the current data point value [CUSTOMER.COMPANY_NAME] CTX['ISIN_CUST'] = CTX['ISIN_CUST'].concat("_").concat("INVALID") ]]> </config> </consDPProcessors> </dataPoint> <dataPoint name="FIRST_NAME" dataType="STRING" /> <dataPoint name="LAST_NAME" dataType="STRING" /> </schema>