Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Default dynamic value in BizForm View modes: 
User avatar
Member
Member
Phil - 5/2/2011 1:32:46 PM
   
Default dynamic value in BizForm
Hello everyone,

I´m trying to create a custom BizForm, which has a textbox PageTitle. Default value of this textbox has to be a title of concrete page, which contains the BizForm.

I´ve tryed it yet, but it does nothing...

1) I´ve cloned the BizForm webpart.
2) In folder CMSWebparts/BizForms i´ve copied bizform.ascx and bizform.ascx.cs and renamed it with specific name of cloned BizForm.
3)I opened the new c# file and into method OnContentLoad() i´ve added code same as http://devnet.kentico.com/Knowledge-Base/BizForms/Setting-default-values-for-BizForm.aspx
4)I´ve edited the code like this:

Control ctrl = BizFormNew.BasicForm.FindControl("PageTitle");
//You should specify 'Column name' attribute from 'CMSDesk -> Tools -> Biz form -> Edit appropriate BizForm -> Fields -> select appropriate field' as parameter for FindControl method.
if ((ctrl != null) && (ctrl is TextBox))
{
((TextBox)ctrl).Text = page.Title;
}


What is bad? Thank you for quick answers!
Phil

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/2/2011 2:56:22 PM
   
RE:Default dynamic value in BizForm
Hi,

That article is pretty old :-)

In newer version it is much easier to achieve your need. Just by using macro expressions.

In the field's default value setting you will use macro like this:
{%cmscontext.currentpageinfo.documentpagetitle%}

Also, here you can find more info about using macros with bizforms.

User avatar
Member
Member
Phil - 5/3/2011 7:59:51 AM
   
RE:Default dynamic value in BizForm
Thank you,

it looks, that macros are pretty cool!
But your macro didn´t work, so I used this one: {(0)%CurrentDocument.NodeID|(equals)192|(falsevalue){(1)%CurrentDocument.DocumentName%(1)}|(truevalue){(2)?title\|(regexreplace)\-(with) ?(2)}%(0)}

from forum page http://devnet.kentico.com/Forums/f46/t19829/Help-with-macro-for-page-title.aspx

Phil

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/4/2011 3:34:05 PM
   
RE:Default dynamic value in BizForm
Hi,

I am sorry for the confusion, I used wrong macro. You should use this one:

{%cmscontext.currentdocument.documentpagetitle%}

Also, please make sure that the page where the bizform is has some page title set in the Properties -> Metadata section.

The second macro you used is very specific for the setup of the other user from the other thread where the user was reading some value from query string parameter. And also, as you can see on my mistake, you have to select correct macro. Anyway, this macro is similar to that one, just slightly modified not to use the query string:

{(0)%CurrentDocument.NodeID|(equals)192|(falsevalue){(1)%cmscontext.currentdocument.documentpagetitle%(1)}|(truevalue){(2)%CurrentDocument.DocumentName%(2)}|(user)michalv|(hash)c3e61160fbab3956cbe12f398950c650519a55b6e684383b21e0b5bd5a9fc0ac%(0)}

Best regards,
Juraj Ondrus

User avatar
Member
Member
nvpat - 7/21/2011 12:35:03 PM
   
RE:Default dynamic value in BizForm
Hi there.

I need to populate a bizform with values from an external database, so Macros won't do the job in my case. I also saw the article at http://www.kentico.com/DevNet/Knowledge-base/API-and-Internals/Setting-default-values-for-BizForm.aspx, but when you say "that article is pretty old", do you mean that method no longer works? If not, how would I go about doing this in version 5.5R2?

Thanks.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 7/22/2011 2:55:53 AM
   
RE:Default dynamic value in BizForm
Hi,

I do not see any reason why macros won't work - you will create a custom macro and its code you can connect to the external source and get the data you want.

Regarding the article - it was just a funny note - the principle and idea is still the same and basically, those are standard .Net things how to read data from query string and how to fill some form controls with it. Moreover, at that time there was no "default value" setting for the bizform fields nor query string macros which you can easily use in newer versions in the field settings.

Best regards,
Juraj Ondrus

User avatar
Member
Member
nvpat - 7/25/2011 10:20:25 AM
   
RE:Default dynamic value in BizForm
Thanks for the reply.

The problem with the custom macro solution is that it is on a per-field basis, so to do it "cleanly", I would have to reconnect and re-query the data source for each field, when in fact I have six fields on the form which come from the same data table, so doing it all at once would be far more efficient (notwithstanding any query caching SQL Server may or may not do).

I suppose it might be possible to query and manually cache all the values at the first custom macro call, and then return the rest on demand without re-querying, but that becomes needlessly complicated real quick.

The reason I asked if the original article was still valid is because the original poster in this thread said he tried it and it didn't work, so I didn't want to try it myself if it was wasted effort. If it in fact still works, it appears to be the most efficient way to do what I'm trying to do.

Thanks.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 7/26/2011 2:45:22 AM
   
RE:Default dynamic value in BizForm
Hi,

I do not see any issue why it should not work. I guess that in the first post just the page.Title was not filled with correct values.

However, you can use caching inside the custom macro code using the CacheHelper class.

Best regards,
Juraj Ondrus