Business Central and Multiline Fields

This topic is probably as old as the RTC client. If you want to display a text field on a Page you will try for around two hours and then you will give up and maybe build a control addin to solve this.

In the web client this problem was not solved by now. We have fields with length up to 2048 but we are not able to display this.

If you go the normal way you use this:

But the result is frustrating:

Correctly! We get three lines of text. And I tried everything with groups and grids. It did not change.

But this post is not about how bad everything is, I want to present you a solution how this can be done better without any custom control addin.

I may introduce you to the “Microsoft.Dynamics.Nav.Client.WebPageViewer”. This is an awesome small controladdin shipped by microsoft. You can not only embed webpages in Buisness Central but you can also pass your own html!

This is what you need to do:

usercontrol(UserControlDesc; "Microsoft.Dynamics.Nav.Client.WebPageViewer")
{
	trigger ControlAddInReady(callbackUrl: Text)
	begin
		IsReady := true;
		FillAddIn();
	end;

	trigger Callback(data: Text)
	begin
		Description := data;
	end;
}
var
	IsReady: Boolean;

trigger OnAfterGetCurrRecord()
begin
	if IsReady then
		FillAddIn();
end;

local procedure FillAddIn()
begin
	CurrPage.UserControlDesc.SetContent(StrSubstNo('<textarea Id="TextArea" maxlength="%2" style="width:100%;height:100%;resize: none; font-family:"Segoe UI", "Segoe WP", Segoe, device-segoe, Tahoma, Helvetica, Arial, sans-serif !important; font-size: 10.5pt !important;" OnChange="window.parent.WebPageViewerHelper.TriggerCallback(document.getElementById(''TextArea'').value)">%1</textarea>', Description, MaxStrLen(Description)));
end;

What did I do there?

The HTML Control I used is a simple <textarea>. With maxlength you want to limit the field to the length of you text field on you table. In my case this is 2048. With the style tag, I set width and height to the max size of the space there is for this control addin.

Now the magic: With the OnChange setting of the textarea I defined what happens if the content is changed. This does not happen on every letter you type but if the textarea looses focus. The TriggerCallback function then passes the content of this textarea to our “trigger Callback(data: Text)” function. There we can simply write the content back to the table field.

Feel free to try this and give me some feedback, maybe there is still something to improve!

20 thoughts on “Business Central and Multiline Fields

  1. Ahaa, its pleasant dialogue regarding this piece of writing
    at this place at this weblog, I have read all that,
    so at this time me also commenting at this place. I’ve been browsing online more than 3 hours lately, yet I never discovered any fascinating article like yours.
    It’s beautiful price sufficient for me. In my view,
    if all website owners and bloggers made good content material
    as you probably did, the net shall be a lot more helpful
    than ever before. There is definately a lot to learn about this issue.
    I like all the points you made. http://foxnews.co.uk

    My homepage: Jason

    Liked by 1 person

  2. Way cool! Some very valid points! I appreciate you penning this article and the rest of the site is also very good.
    Howdy! This blog post couldn’t be written any better! Going through
    this article reminds me of my previous roommate! He constantly kept preaching about this.

    I’ll forward this article to him. Pretty sure he’s going to have a great
    read. Thanks for sharing! Heya i am for the primary time here.
    I found this board and I in finding It truly useful & it helped me out much.
    I am hoping to present one thing again and aid others such as you aided me.
    http://Linux.com/

    Here is my blog … Jack

    Liked by 1 person

  3. Definitely consider that which you stated. Your favorite justification seemed to be on the net the simplest factor to keep in mind of. I say to you, I definitely get irked even as other people consider concerns that they plainly do not realize about. You controlled to hit the nail upon the highest and also defined out the whole thing without having side-effects , other folks can take a signal. Will probably be again to get more. Thank you

    Liked by 1 person

    1. The addin should be available without installing anything as it is part of the base app shipped by microsoft. The rest of the code needed is available is this blog.

      Like

  4. Thanks for the great post!

    I am trying to implement it in Business Central 14.0 OnPrem in C/AL. It works in RTC, but in WebClient I always got a method ControlAddIn not Found error message. I also tried to modify the manifest.xml to leave out the CDATA line for ControlAddInReady and leave the Startup JavaScipt call only, but the same happens.

    Any ideas, how to solve the issue? Thanks for your support!

    Like

  5. Very nice post.

    I copied your code but it didn’t worked. On the page it doesn’t show up anything until i realized i had to add the AplicationArea Parameter in the usercontrol.

    Like

  6. Great post. Besides the onChange trigger on the TextArea you could (also) implement the onInput trigger to ensure your Description field will be updated

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: