Reference picker offers entries that violate its mandatory where rule (and then cannot be saved)

Hi all,

(application model: 108)

I am building PPWR (EU packaging regulation) compliance in our ERP. A simplified version of the model:

  'PPWR Documents': collection ['ID'] {           // supplier declarations, test reports, ...
      'ID': text
      'Components': collection ['Component'] {    // the components this document tells us something about
          'Component': text -> ^ ^ .'Packaging Components'[]
      }
  }
  'Packaging Components': collection ['Name'] {
      'Name': text
      'Food Contact': stategroup (
          'No' { }
          'Yes' {
              // the document that proves this fact
              'Evidence': text -> ^ ^ .'PPWR Documents'[] as $
                  where 'Reading' -> $ .'Components'[ ^ ]    // only documents that mention THIS component
                  where 'Proof' ~> 'Reading'.'Food Contact Declaration'?'Available' //only documents that mention Food Contact
          }
      )
  }

So within a component we point at the PPWR Document that proves (or disproves) compliance. A user should only be able to choose a document that actually says something about this component.

What happens in the generated web client (see screenshot): the Evidence picker lists every PPWR Document, including ones that have no row for this component. If I pick one, the field gets “Violates constraint: Reading” and the form cannot be saved. So the rule does validate, but the picker still offers options that can never be saved.

Sidenote: within the screenshot you’ll notice a Documents union colleciton using an inverse reference-set to list all Documents that use THIS component. This is a workaround I use more often, but I am not sure whether it is best practise.

My question therefore:
Is there a way to make the picker offer only the entries that satisfy the where rules?

Thanks!

Hi Martinique,

The first where rule is a containment rule (with lookup key between the [ and ] ), which is not supported yet in the client selection window. It is best to replace it with a ‘normal’ reference to an actual collection (based on a reference-set on the Component reference)

The second where rule is now optional and will therefore not be checked. I do think we should add a filtering capability in the selection window, but it isn’t there yet. You could add a @validate: resolvable after that where rule to get it to filter, if I am right.

Where rule support in the client is being improved all the, I do not yet know when these types of rules will be fully supported, I am checking that for you.

1 Like

We expect to add support for the remaining where rules during the next half year. No rush, as there are workarounds (as I explained).

Thank you for your help Rick. Code looks like this now. That works perfectly fine and scopes down to only the Documents that proof this Component does (for example) Contact Food. Also included a validation stategroup with a todo in case something changes after it has been chosen.

'Evidence': text ~> <- ^ .'Documents'[] as $
	where 'Proof' ~> $ >'Reading'.'Food Contact'?'Yes' @validate: resolvable
'Proof': stategroup = switch .'Evidence'&'Proof' (
	| node => 'Valid' ( )
	| none => 'Not Stated' ( )
) (
	'Valid' @style: success { }
	'Not Stated' @style: error {
	   has-todo: user ....
	}
)
1 Like