A Sweagle validation policy (validator) is assigned to at least 1 CDS (the "primary" CDS), but can also work with additional CDS. This allows to create a validation logic which spans configData from multiple CDS. As an example, one could create a validation logic which checks that the dbConnectionString is different in every environment for a given application (in case there is a CDS for every environment).

The content of every assigned CDS is accessible in the parser logic through the variable "metadatasets" (of type array).

the metadatasets variable (type array)

The primary CDS

The primary CDS (to which the validation policy is assigned) is accessible as the first array element, while the additional CDS are sequentially added as the next elements in this array.  Every element in this array is a json object which contains all the nodes and its associated CDIs.

The snapshot content of the primary CDS can be accessed through the metadatasets[0] array's element.

As an example, accessing a CDI which is defined at a node node directly in the root of the CDS snapshot can be done using :


You can also use the dot notation although that is only possible in case there are no . in the nodeNames or keyNames.

The additional CDS

the additional CDS are accessible as subsequent array elements in the metadatasets variable. Additional CDS are added as array elements, starting with index 1 to x, in the sequence in which they have been assigned to the validation rule policy. 

As an example, in case you create a validator which requires exactly 1 additional CDS, you can define a logic which checks that the metadatasets array contains only 2 elements. If not, it will return a controlled script error as a response. 

if (Array.isArray(metadatasets) && metadatasets.length!==2){ 
  return {'result':false,'description':'validation policy error: this validation requires exact 1 primary and 1 additional CDS'}; 

Article Information

Last Updated:2020-10-15 01:03:14