Structure Mandatory Attribute Validation

Structure Mandatory Attribute Validation

  

Suppose that I have a variable with structure type. This structure has some mandatory attributes.

How can I validate if this variable has all mandatory attributes filled out correctly?


Please, do not respond that I have to do it manually. This is not a nice solution!

Among the widgets you have the input fields. They all have a property called IsValid. If a mandatory field isn't filled, it won't be valid. If a numeric input as text, it won't be valid, etc.


Or you can just try to save and catch the error when it crashes.


Nuno Reis wrote:

Among the widgets you have the input fields. They all have a property called IsValid. If a mandatory field isn't filled, it won't be valid. If a numeric input as text, it won't be valid, etc.


Or you can just try to save and catch the error when it crashes.



I know about of the IsValid properties on widgets.
I'm not using views and widgets. I have olny the variable.

Actually I'm using API REST and I need that all mandatory fields are filled out to call the next service.

Hi Nuno.

Save to see if it works is not a nice solution. ;) lol And is worse,  as the chance to fail is very high.

For example, mandatory fields will throw an exception only if they are FKs. For the other fields, the database will not complain if they are empty.

Joao,

Sorry to say that, but other than attaching it to a page with input fields in a form, I'm not seeing too many options.

You can try to create an extension that receives the information and look the metadata to see if the information is valid.  But even in this case, you would have to create at least a generic code. Looking in the metadata, maybe would be possible to do this inside OutSystems, but than it would be specific by entity/structure.

I don't know if there is any forge component able to do this, but I don't think.

Cheers,

Eduardo Jauch


Eduardo Jauch wrote:

Hi Nuno.

Save to see if it works is not a nice solution. ;) lol And is worse,  as the chance to fail is very high.

For example, mandatory fields will throw an exception only if they are FKs. For the other fields, the database will not complain if they are empty.

Joao,

Sorry to say that, but other than attaching it to a page with input fields in a form, I'm not seeing too many options.

You can try to create an extension that receives the information and look the metadata to see if the information is valid.  But even in this case, you would have to create at least a generic code. Looking in the metadata, maybe would be possible to do this inside OutSystems, but than it would be specific by entity/structure.

I don't know if there is any forge component able to do this, but I don't think.

Cheers,

Eduardo Jauch


Hi Eduardo,

Thanks for your response. Unfortunately I believe that is an unsolvable problem. I don't know if somebody already has this kind of situation. Validate a message form REST API is very difult in OutSystems.

About create some extension could be another problem. I would have to use something like reflection to iterate all attributes and validate each value. Don't think it's possible.

Regards,

JP



Well said Eduardo!

João, I'm not seeing any component that can magically determine the structure and all the mandatory inputs. You may need to do a specific action for each structure and call it on each variable.

Joao Oliveira wrote:

Thanks for your response. Unfortunately I believe that is an unsolvable problem. I don't know if somebody already has this kind of situation. Validate a message form REST API is very difult in OutSystems.

About create some extension could be another problem. I would have to use something like reflection to iterate all attributes and validate each value. Don't think it's possible.

Regards,

JP

Hi Joao.

Validate a message is not difficult. It just gives some work. ;)
But, Why to you think create an extension that uses reflection is not possible?

Cheers,
Eduardo Jauch


Eduardo Jauch wrote:

Joao Oliveira wrote:

Thanks for your response. Unfortunately I believe that is an unsolvable problem. I don't know if somebody already has this kind of situation. Validate a message form REST API is very difult in OutSystems.

About create some extension could be another problem. I would have to use something like reflection to iterate all attributes and validate each value. Don't think it's possible.

Regards,

JP

Hi Joao.

Validate a message is not difficult. It just gives some work. ;)
But, Why to you think create an extension that uses reflection is not possible?

Cheers,
Eduardo Jauch


Would be dificult if I have too many structures to validate. Yes, it's no complicated but will be a lot of work to get it done.  :\

I'm sorry if I am missing something but I don't know how to create an extension to receive any kind of structure and based on OutSystems metadata validate each value.

In my experience developping extensions I need to create the structure (or maybe an object) at the extension to be a valid parameter. This will make my code very hard to maintain because I'll need to expose this structure (or a clone) on my exposed APIs.

Am I making this more dificult than is in reality?

If there is a simple way. How could be done?

Joao Oliveira wrote:

Eduardo Jauch wrote:

Joao Oliveira wrote:

Thanks for your response. Unfortunately I believe that is an unsolvable problem. I don't know if somebody already has this kind of situation. Validate a message form REST API is very difult in OutSystems.

About create some extension could be another problem. I would have to use something like reflection to iterate all attributes and validate each value. Don't think it's possible.

Regards,

JP

Hi Joao.

Validate a message is not difficult. It just gives some work. ;)
But, Why to you think create an extension that uses reflection is not possible?

Cheers,
Eduardo Jauch


Would be dificult if I have too many structures to validate. Yes, it's no complicated but will be a lot of work to get it done.  :\

I'm sorry if I am missing something but I don't know how to create an extension to receive any kind of structure and based on OutSystems metadata validate each value.

In my experience developping extensions I need to create the structure (or maybe an object) at the extension to be a valid parameter. This will make my code very hard to maintain because I'll need to expose this structure (or a clone) on my exposed APIs.

Am I making this more dificult than is in reality?

If there is a simple way. How could be done?

Thanks god exist the "Object" ;)
You can pass any datatype in OutSystems, to an extension, converting it to Object.

And inside the extension, use reflection to work with it :)

I think this can solve the problem.
And I'm pretty sure I already saw something here in the forum related to this.


Nuno Reis wrote:

Well said Eduardo!

João, I'm not seeing any component that can magically determine the structure and all the mandatory inputs. You may need to do a specific action for each structure and call it on each variable.

Hi, Nuno.

I'm not asking for magic. Structures are OutSystems objects and have a "mandatory" property. Would be nice if they could validate itself just like widgets do in views.

Unfortunately validate each strucuture with a specfic action would be a lot of work for me. I have more than a 100 structures to validate.

Create more than 100 actions to validate each structure and maintain all that, sounds bad to me. I'm not saying that is impossible. I believe it's non-productive.

Joao Oliveira wrote:

Suppose that I have a variable with structure type. This structure has some mandatory attributes.

How can I validate if this variable has all mandatory attributes filled out correctly?


Please, do not respond that I have to do it manually. This is not a nice solution!

Hi Joao Oliveira

Is it a complex or simple structure? 


Hanno Coetzee wrote:

Joao Oliveira wrote:

Suppose that I have a variable with structure type. This structure has some mandatory attributes.

How can I validate if this variable has all mandatory attributes filled out correctly?


Please, do not respond that I have to do it manually. This is not a nice solution!

Hi Joao Oliveira

Is it a complex or simple structure? 


It's a complex structure. Including lists


Hmm, you could make a map of your structure, in which you determine which fields are mandatory and what their datatype is (datatype could be anything you can determine different validations for, like email or phone number).

You would still have to make some actions that iteratate through the values and do the validation for them.


But it definitely beats out doing it manually plus it is probably reuseable for other things too, (I don't think there is a thing you can use to check if a attribute is mandatory right? If there is you can probably leave that out in your map structure or whatever)