Best way to trim strings longer than fixed string length?
0
When assigning a pretty long string to a string attribute with a fixed length you get an error in Mendix: Attribute 'MyFirstModule.Target.AttributeLength20' has a maximum length of 20, tried setting a value of length 1020. at MyFirstModule.Microflow_9 (CreateAndChange : 'Create Target(AttributeLength20, AttributeLength40, AttributeLength20, AttributeLength40)') A solution offcourse is to trim the string to the maximum length with a construction like: if length($Source/StringUnlimited) > 20 then substring($Source/StringUnlimited, 0, 20) else $Source/StringUnlimited Is there a more convenient to way to solve this issue, when you for example have to create an entity with 30 fixed-length-string-attributes. Do you have to copy the above code 30 times or is there an easier / shorter solution? Unfortunately you seems to always need the length check because when only using e.g.: substring($Source/String18, 0, 20) you might get an error when the source string is shorter than 20 characters: java.lang.StringIndexOutOfBoundsException: begin 0, end 20, length 18 Regards, Edwin
asked
Edwin van Elk
2 answers
1
// how about
substring($Source/String, 0, min(20, length($Source/String))
answered
Andrej Gajduk
1
Why not create a microflow that does your magic, with the max lenght and an unlimited strings as input and an unlimited string as output.