Placing form dataproviders into JS variables?

Newbie question. I have a task where I need to combine several data providers into one sentence on a form and display it in a label:

Form Datasource: table “persons”

For example the label should look as follows:

<first_name> is <age> years old.

I can probably place dataproviders for <first_name> and , make them hidden, bind them to form variables and use those variables to compose the label.

Is there a more straight-forward way of doing this? I wasn’t able to immediately find it in docs/forums.

First, set ‘Display Tags’ property to true on your label. Next, in the text property of the label add this:

%%first_name%% is %%age%% years old.

If I understood your question, that should answer it for you.

Keith

I need to add a substring function to one field, sorry I omitted in in the original question. I thought it were possible to somehow place dataprovider into a JS variable:

<first_name> is <age> years old. He said <comment.substring(1,100)>

Which would place first 100 characters of the comment. Is there a way of doing this?

The only way to use dataproviders within a text string directly on a label is the way CFDaddy showed you in his post.
There’s no option to use text-functions here.

What you could do however, is create a calculation in your table and use that new calculation as dataprovider on your label.
You’ll find calculations here: databases > myDb > myTable, open the table and choose the calculations tab from the editor window.

Calc should look something like this:

function comment_short() {
     return comment.substring(1,100);
}

Now use ‘comment_short’ as a tag on your label like:

%%first_name%% is %%age%% years old. He said %%comment_short%%

Not so great for a solution. :( I was hoping to be able to directly fetch dataproviders into JS variables. Will work around it by placing pre-calculated string into a database column.

sergei.sheinin:
Will work around it by placing pre-calculated string into a database column.

If you don’t ever need this in a query, this is absolutely not the way to go.
If you want the total text in a table dataprovider though, create a calculation as I pointed out before, but this time like:

function myText() {
     return first_name + " is " + age + " years old. He said " + comment.substring(1,100);
}

This way you will have an unstored dataprovider in your table.
As long as you don’t use relations in your calculations, it’s a great concept!