Hi ,
How can we apply string data validation in the textfield in Appian. I have a requirement in which the first two alpahbets, should be either a or A and the second one will be c or C. In short for a particular string , how can i check the character value at a particular index and apply validation.
Discussion posts and replies are publicly visible
In addition to charat(), you might also check out the function left(); left("aces", 2) would result "ac", which should satisfy your use case. I'll post a more expansive code sample here, just to be thorough:
a!textField( label: "My Text", value: ri!textInput, saveInto: ri!textInput, validations: { if( upper(left(ri!textInput, 2)) = "AC", null(), "Text must begin with the string 'AC' (case insensitive)." ) } )
hi mike , sorry for late reply , what if i want that the input text (string) is of MM/YYYY format , i am using validation on text filed. I have to extract only month and year and save them into db in mm/yyyy format
You add to yourself far greater work of avoiding months like 99, 55, AJ, RJ, GG, QQ, $%, **, or years like 1527, 1066, 9999, 4597, or "Spider-Man 2099" or "Steve Jobs' Birthday".
It's so much simpler to just use the component that's already designed to prevent users from inputting anything other than a date.
Could you also use dropdown fields to limit their options? If you provide a dropdown for month and year right next to each other, a validation wouldn't be necessary because you would only display months and years that are valid.
Date field or paired dropdowns work really well. One of the key principals of good UX is to, where possible, make it extremely difficult for the end user to make a mistake.
i tried that , but the date field calender thing should not be visible to end user, so thats why im using the text field with validation ,
a!textField( value: ri!monthEndCDT.monthendkey, saveInto: { ri!monthEndCDT.monthendkey }, validations: if( and( like( ri!monthEndCDT.monthendkey, "[0-9][0-9]/[0-9][0-9][0-9][0-9]" ), len(ri!monthEndCDT.monthendkey<7)), "valid date", "enter valid date Value MM/YYYY" ), ),
But this is displaying error message in both cases, valid and invalid both. It works but for valid value also , it displays red errored out textfield
So when you set up a validation in Appian, the result of the validations parameter should either be some text (which is what will display as the error message) or null. If a text is returned, Appian assumes that a validation should be triggered, while null means no validation should show. If you want to use the expression above, you will probably need something like this:
a!textField( value: ri!monthEndCDT.monthendkey, saveInto: { ri!monthEndCDT.monthendkey }, validations: if( and( like( ri!monthEndCDT.monthendkey, "[0-9][0-9]/[0-9][0-9][0-9][0-9]" ), len(ri!monthEndCDT.monthendkey<7) ), null, "enter valid date Value MM/YYYY" ) )
That being said, I still wouldn't recommend using a text field for this - two dropdowns would probably work a lot better and be more clear for the user.
Hi , thanks it works when i replace that with null. i tried using that with dropdwon also, but i got an error . its basically an editble grid . i need to save month end key in mm/yyyy format. for dropdown , i have made 2 dropdown for year and month. But when i click on add rows dynamic link , error is there.
Interface Definition: Expression evaluation error at function a!forEach [line 60]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function a!dropdownField [line 90]: A dropdown component [label=“”] has an invalid value for “value”. Value cannot be null.
a!dropdownField( ------------->>>> line 90 choiceLabels: { "jan,feb,march" }, choiceValues: { "jan,feb,march" }, value: local!month, saveInto: local!month ), a!dropdownField( choiceLabels: { "2020,2021,2022" }, choiceValues: { "2020,2021,2022" }, value: local!year, saveInto: local!year ),
my plan is to take both these local values , append them , include a "/" string in between and save in the ri!monthEndCDT.monthendkey.
included a null check also for this ,
a!dropdownField( choiceLabels: { "jan,feb,march" }, choiceValues: { "jan,feb,march" }, value: if(isnull(local!month),{},local!month),
i am not sure how this thing works, initially year and month variables will be null only , user will enter the values.
When you have a dropdown field whose value will initially be null (so, most of the time), you need to also set a "placeholder label" value -- this is usually just text that will help the user know what to do, and shows up when the value is NULL, but doesn't count as a valid selection if the field is required. Setting this correctly will cause your error message to go away.
e.g.
a!localVariables( local!year, a!dropdownField( choiceLabels: { "2020", "2021", "2022" }, choiceValues: { "2020", "2021", "2022" }, value: local!year, saveInto: local!year, placeholderLabel: "--Select Year--" ) )
(also, i fixed the choiceLabels and choiceValues - these should be arrays, the way you had them they were just strings that would cause them to only show up as one option instead of three)
Thanks mike , both the approach works fine. I had this last doubt , like in documentation how is text(38353, "mmm/dd/yyyy") returns "Jan/03/2140"(Text) . Actually i thought of using text function to convert input value to date type string. How this date is being calculated?
In general for dates, the text function is really only useful if the value you're starting with is an actual date value - i.e. "text(now(), "mmm/yyyy")" would work well, but i don't know if it would work very well with inputs that aren't a date value or something corresponding to this.