Ui Path Forms vbnewline not working

I created a form to get customer input and based on the input generate a output “CME Validation Error”. Would you happen to know if I can have each variable in a new line and if that variable is null not to show in the output. Below is an image of the form and the variables I am assigning to the output variable.


Assigned the below to an single variable then tied that to an argument going into the form.
noMatchCaseNumber + VbNewLine+
noMatchFirstName + VbNewLine+
noMatchLastName + VbNewLine+
noMatchBodyStatus

Hi @syi,

Try using vbCrLf instead.

I like Environment.NewLine, much easier to read (and remember). vbcrlf is outdated, I would say. There is also a stackoverflow post about why Environment.NewLine is more preferrable.

1 Like

Thanks, that’s good to know.
Also thanks for sharing the stackoverflow article.

1 Like

Hello,

Tried both methods but still the same results.

One thing I also noticed is when I tried below I get a complier error:

can the value in the form field collection only take one variable?

Wonder you are using to display validation error message?

Environment.Newline should work. For example, a message box with "test " + Environment.NewLine+"test 1"+Environment.NewLine

test

In terms of compilation error, you probably has some invalid cast. It is hard to see given the incomplete screenshot there.

1 Like

@syi
the argument is of type in/out
the l-Value exception is thrown as it is excpecting a clear destination where to store the value

it should be get fixed by

  • changing the direction to only out
  • to define a variable, get initialized with the different matchresult values and new lines (as you have done in the screenshot) and using this newly created variable for the in/out argument

Good call, I missed that.

It needs to be changed to In, then you can set value. If it is out or in/out, it must be stored in a variable.

Hello,

I tried changing the direction to out but when I do I get an empty box
image
I checked the output to a message box and that seems to work


Output to message box will show as new line but when I use the same variable in forms it does not.

Hi @syi
That is to be expected. Here’s a revision of the basic differences in directions and when you might use what:

  1. IN - If you want to send a value TO the form, either to display or use for some calculations.
    If you end up changing the value, it won’t reflect into your main workflow once the form is submitted. It only goes one way - inward
  2. OUT - The exact opposite, a value that your form gives back to the workflow, but it may not exist before calling the form. The easiest example is any user input - you present an empty field and whatever user enters/selects - is the OUTPUT from your form.
    Only outward
  3. IN/OUT - This is when you want to send a value in but also expect to know about any changes to its value during the course of the form execution.
    An example could be that you’re getting an OCR extracted data validated from a user through a form. You present what the bot was able to capture and get the user to correct it if necessary.
    The output will reflect into your workflow when the direction is two-way.

Now what @ppr and @ui_xpath are saying is that when setting direction to IN/OUT, it needs to be a SINGLE variable in the field. Referring to the explanation of IN/OUT above, because you want to read back whatever was changed, it should be ONE variable where the workflow will store it for further use.

In your screenshot above, continue to use IN/OUT if you need, just use a single variable that represents ‘matchValidationError’ variable, instead of the constructed string of 3 variables

To avoid confusion and as a good practice, please consider adding a prefix to your arguments:

  • in_ (for IN direction)
  • out_ (for OUT direction)
  • io_ (for IN/OUT direction)

followed by the variable name from the workflow.

2 Likes

Hello
Thank you for the explanation it was very helpful.

What I still don’t get is why the output to FORM shows everything on a single line where the output to MESSAGE BOX will create new line where Environment.NewLine is used.

So when I assign:
var1 + Environment.NewLine +
var2 + Environment.NewLine+
var3 + Environment.NewLine +
var4
to varTotal

in FORMS varTotal shows as:
var1 var2 var3 var4

in MESSAGE BOX varTotal shows as:
var1
var2
var3
var4

Not sure what I am missing where FORMS is ignoring the Environment.Newline command.

It turns out that it doesn’t matter if you use Environment.NewLine or \n. To get the line breaks rendered correctly, don’t disable the Text Area component. But how do I prevent the user from entering text in that area? Edit the JSON and add the readonly attribute instead.

image

1 Like

@syi Can you try using the <br> tag along with the String. For Example :

If var1 and var2 are your value variables, then use the below expression and check :

var1 +"<br>" + var2

@ptrobot THANK YOU!!! that worked perfectly.

One more question though.
How can I make null variable not take up space:

For example:
var1 + Environment.NewLine +
var2 + Environment.NewLine+
var3 + Environment.NewLine +
var4
to varTotal

if only var1 and var3 have value in forms it shows as:

var1
(empty space)
var3
(empty space)

For message box I was able to solve this problem by doing “varTotal.trim” but when I tried the same in forms I get a complier error.

@syi You’re welcome! Good to hear that’s working.

You could use Split() with the option RemoveEmptyEntries, e.g.

varTotal = String.Join(Environment.NewLine.ToCharArray, varTotal.Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries))
1 Like

@ptrobot Thanks again for your help!!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.