You can use the substring function to limit the length of the string. Add a check before to see if you need to do this by checking the length with the length function.
If you have string in the $MyString variable, something like this should work.
if (length($MyString) > 30) then
substring($MyString, 0, 30)
else
$MyString
https://docs.mendix.com/refguide/string-function-calls/#4-length
https://docs.mendix.com/refguide/string-function-calls/#5-substring