App Studio - Text Area w/ Line Breaks

So, trying to put the finishing touches on a dashboard and this is bugging me. I’m giving the user the ability to enter a comment into a TextArea, which is being saved to a ud column.

Initially looks good… saves.
image

If I then re-open that record… it comes back in looking like this:
image

Looking at the dataview, it is being saved as this:
image

So, it is taking my hitting the “enter” key when entering the text and injecting a “\n” (new line).

What I really need is a “\r\n” Carriage Return Line Feed.

… or even \r (Char13). I’ve proven this based on the Part Descriptions I imported via DMT where I included Char(13).

They appear like this:
image

and the dataview includes this:
image

I have been playing around with various expressions in my row-update to “replace” the \n with \r\n… but not finding the special sauce.

I’ve been playing around with things like:

#_'String original = '{TransView.AdjComments}'; original.replace("\n","\r\n")'_#

… but… I get an error:

function body 'String original = 'Line 1Line 2'; original.replace("\n","\r\n")' thrown exception SyntaxError: Unexpected identifier 'Line'

So, it appears, here, even though the dataview shows the \n (pictured above) the expression doesn’t see it, as it is just showing the original string as

Line 1Line2

Was hoping I could programmatically pull this off.

I’ve tried simplifying to just:
#_({TransView.AdjComments}.replace("\n","\r\n"))_#

But errors as:
function body Line 1Line 2; replace("","") thrown exception SyntaxError: Invalid or unexpected token

.replace may not be supported at all in this case.

Anybody have any thoughts? I’m just throwing things at the wall at this point hoping to get lucky. Not even sure if this is doable in a row-update expression.

… and I’ll apologize in advance as I type this up, its the end of my day so I have to run to pick up my kids. But, I’ll try any lobbed suggestions in the morning!

Thanks in advance.

3 Likes

Fix it in a bpm. No guarantee that javascript will work long term.

Probably want to report this as a bug as well.

1 Like

I’m gonna echo Kevin: fix these things in a function or BPM.

BUT, I kind of got this to work? You need to use Regex to find the value. I can get it to replace it them with a string, but it seems to ignore the carriage return.

'{TransView.TextArea}'.replace(/\\n/g, "\r\n")

(Don’t include the #_ _#)

2 Likes

Thanks @klincecum and @hmwillett,

I did just test Kevin’s route… added a data directive to replace \n with \r\n… also attempted replacing with just \r.

foreach (var row in ttJobAsmbl)
{
    if (row.RowMod == "A" || row.RowMod == "U")
    {
        if (!string.IsNullOrEmpty(row.AdjJobAsmblComment_c))
        {
            row.AdjJobAsmblComment_c = row.AdjJobAsmblComment_c.Replace("\n", "\r");
        }
    }
}

It successfully replaced… But, sadly, the TextArea just seems to ignore them:

Perhaps just a limitation of the Kendo TextArea? Users will just have to deal for now cause I’m tired of trying to work around it.

2 Likes

try \r\n

1 Like

Tried that first.

1 Like

Have you tried changing the text area to a rich text in application studio? The downside will be that users have to save the field separate from saving the record.

1 Like

Haven’t played with Rich Text at all yet. May play with that in a bit. Thanks! I’ll see if that is an improvement.

Well, interestingly, the Rich Text treats the stored value to HTML paragraphs, adding < p> < /p> tags to the value being stored in the dataview:

So… although this comes back in looking correct in the display (in the rich text editor) if I reload the record, I’m a little concerned about having those HTML tags included in the stored value.

I’ll have to see how this may effect reports where I try to pull this value in. I may have to add additional “replace” expressions in SSRS to fix them there.

2 Likes

I’m so glad you are figuring this stuff out so I don’t have to.

5 Likes

SSRS Output: :roll_eyes:

image

… and of course, even if reverting back to:
image

SSRS doesn’t like that:
image

So… guess I need to “replace” in SSRS afterall:

="Sales Cost Adjustment Comments: " + VbCrLf + Replace(Fields!AdjJobAsmblComment_c.Value, CHR(13), VbCrLf)

image

Still doesn’t fix the Kinetic UI (TextArea)… but it’ll show up correctly on the Production Detail Report. So, I’ll take the small victory at least.

In SSRS, you can set the place holder to interpret HTML maybe?
image

1 Like

Yeah, I’ve used that before… but… enough is enough. I’ll wait until someone starts bitching about it in the UI. (you know… sometime tomorrow probably :rofl:)

2 Likes

I got it to work with Text Area. First, don’t bind the Text Area to the DataView that is populated by and used to update the database. Instead, set its EpBinding to e.g. TransView.BreaksDisplay. Create an event to populate this field with your real data, e.g. YourRealDataView.AdjJobAsmblComment_c. I named it PopBreaksDisplay. Use an “After Event” trigger on whatever populates/updates YourRealDataView. The event has a kinetic-function followed by a row-update to overcome these two hurdles: 1) converting your string containing newline chars into an array of strings without them, and 2) recreate the string with newlines.

Create the simple eFx in Epicor Functions Maintenance. Give it one input and one output, both Strings. Design it with this C#: output = System.Text.Json.JsonSerializer.Serialize(input.Split('\n'));.

In the kinetic-function action, fill in Epicor Functions Library and Service Operation with the new eFx’s info and put YourRealDataView.AdjJobAsmblComment_c in Method Parameters → Field Value.

In the row-update action, fill Ep Binding with TransView.BreaksDisplay and Value with "_#JSON.parse('{actionResult.output}').join('\\n')#_".

To make the text in Text Area update your database, simply update it with the value in TransView.BreaksDisplay wherever you were already updating the db.

3 Likes

Nice!

Haven’t tested it yet… but kudos for working around all those obstacles!

hamster obstacle course GIF

1 Like

You can test it without breaking your working version by just adding a new Text Area to the screen somewhere. I understand if you don’t feel the need, it’s good to know this is possible going forward. 95% of the obvious things to try just don’t work, so it’s worth having documented on this forum.