How to user the string length in an struct

Hello,

I need to prefent a string in an Struct will be assigned with an to long value.

So I set te length to an value.

But still I can assing an longer value to it.

Without an exception or warning.

I was searching for help on this but I could not find any.

Does anyone knows whats the use af te length in an Attribute, or what i'm doing wrong so I kan assing an long value to the Attribute2?

Kind regards,


Robert de Vries

Hi Robert,

In the case of the image you show, the length of a Text (string) is the number of characters that the attribute can, at its maximum value.

Cheers,
Nuno

Hello Nuno,

Thats exactly my problem. I set the max length to 5 for Attribute2. But still I can assign "abcdefghijklmnopqrstuvwxyz" to it (26 chars)

I already searched in the documentation thats why I use this length.

This stuct is used to fill an XML and some text fields in this XML have a max. for the text lenghts.

Otherwise I have to check every value before I assing it.

Kind regards,

Robert.

In fact, this is a situation that never happened to me. Would it be possible to pass an OML, with this case, so that I can do some tests? Even if you cannot pass this OML for professional security reasons, try to replicate this case to a separate OML, where this also happens.

Hello Nuno,

Created an very simple application in my personal enviroment.

The OML is attached. 

Nice you want to have a look at it.

Regards,

Robert.

Solution

Hello Robert,

The Length property of a Text attribute has two functions.

1. If the attribute is in an entity, it will define, database-side, how many characters that column will be able to store.

2. When assigning this attribute (from a variable, no matter if the data type is an Entity or a Structure),  it will allow SS to set the Input widget Max. Length property to be set with the same value (in case of a scaffolding), and to warn you if the Input Widget property value is different from the entity/structure attribute length property.

But it will never prevent you from assigning a value with more characters than this length to the attribute of the variable.

That's the reason, for example, if you change the Input Widget Max. Length to a value bigger than the one from the entity and the user enters more characters than the database can hold; when trying to create the record the database raises an exception saying that the text would be truncated.

If you want to enforce a maximum number of characters, you have to enforce it through logic (though the Input Max. can help).

Cheers.

Solution

There is the answer to your question. As I told you, I had never experienced this problem before, and I would have to validate it and try to help you. But Eduardo has already clarified us both. Thank you Eduardo. Thanks Robert.

You're welcome, Nuno :)

Hello,

Thanks Nuno and Eduardo for youre time. So than i have to create logic for this.

I also search if I can read this length from the struct but it seems that is also not possible.

(if I would know the max. length I could create an funtion with that)

The filling of the struct is through an timer so its not possible to use the Widget max. length.

(and the data comes from an external database)

Kind regards,

Robert de Vries