thingworx-field-work / ThingworxVSCodeProject

Develop thingworx models using a real IDE
MIT License
33 stars 17 forks source link

Validator with parameters support in Mashups #74

Closed kklorenzotesta closed 5 months ago

kklorenzotesta commented 5 months ago

I was wondering if is it possible to define a Validator with input parameters in the tsx mashups. Or only validators without parameters are possible at the moment?

BogdanMihaiciuc commented 5 months ago

You can, but there is no typing support for the parameters and there is no fancy way to declare them like with mashup parameters. What you have to do is to create a JSON file that contains the definition of your parameters, which looks like this:

[
    {
        "BaseType": "STRING",
        "DefaultValue": "",
        "Description": "",
        "ParameterName": "test",
        "bindingDirection": "Target",
        "bindingType": "Property",
        "isBindingSource": false,
        "isBindingTarget": true,
        "shown": true
    },
    {
        "BaseType": "NUMBER",
        "Description": "",
        "ParameterName": "test2",
        "bindingDirection": "Target",
        "bindingType": "Property",
        "isBindingSource": false,
        "isBindingTarget": true,
        "shown": true
    }
]

Then, when you create the validator, you have to use a Dynamic namespace to specify the properties that it creates based on its configuration. Namely these are the hidden parameter defs property and the bindings for your parameters:

<Validator
    Dynamic:_currentParameterDefs={importJSON("./ValidatorParameters.json")}
    Dynamic:test={QueryImplementingThings.SelectedRows.name}
    Dynamic:test2={10}
    Expression="test.length == test2"
    AutoEvaluate
    True={[QueryImplementingThings]}
/>

Expression and likely the new Validator2 and Expression2 also work the same way.

kklorenzotesta commented 5 months ago

That's great! thank you very much for the help!