I am basically using a wizard to generate report and pretty much of VS2k10's "built in" Designer so looks like this is the appropriate branch to post the report.
I am trying to pick just the first name from the Northwind DB field and looks like split can do so. Well I am trying to use this in the expression editor :
=
IIf(IndexOfSubstr(Fields.ContactName,
" "
) >
0
, Split(
" "
, Fields.ContactName),
"False"
)
Evidently, and that gives me "System.String[]" but if I try expression as below :
=
IIf(IndexOfSubstr(Fields.ContactName,
" "
) >
0
, Split(
" "
, Fields.ContactName)[
0
],
"False"
)
I get this message : An error has occurred while processing Report 'DemoReport2': Missing operator before '[0]' operand.
Just to make my self clear I tried this and that works, may be I am missing something ?
System.String[] s =
new
string
[] {
"telerik"
,
"reporting"
};
Console.WriteLine(s[0]);
Please comment ...
This is the query I am using:
SELECT
Orders.CustomerID,
Customers.ContactName,
Orders.OrderDate,
Orders.RequiredDate,
Orders.ShippedDate,
Orders.ShipVia,
Orders.ShipCity
FROM
Customers
INNER
JOIN
Orders
ON
Customers.CustomerID = Orders.CustomerID
Thanks,
-Aarsh
7 Answers, 1 is accepted
There is no expression iterator that can be used with a field returning a collection of objects, so instead of splitting the text, you can use the following expression to extract the first string before a space character:
= IIf(IndexOfSubstr(Fields.FullName, " ") > 0, Substr(Fields.FullName,0,IndexOfSubstr(Fields.FullName, " ") ), "False")
I hope this helps.
All the best,
Stef
the Telerik team
Telerik Reporting Q1 2013 available for download with impressive new visualizations. Download today from your account.
If there aren't any, I would like to kindly request the demo so that I can actually add a small C# Class Library to have my userdefined function that I can use as black-box.
Thanks,
-Aarsh
In order to handle array values in an expression, our suggestion is to utilize an user function. Check out the following sample:
public
static
string
GetArrayItem(
string
[] values,
int
index)
{
return
values[index];
}
Then you can use the following expression:
= IIf(IndexOfSubstr(Fields.ContactName,
" "
) > 0, GetArrayItem(Split(
" "
, Fields.ContactName),0),
"False"
)
Generally handling arrays in expressions is in our TO DO list.
Kind regards,
Stef
the Telerik team
Telerik Reporting Q1 2013 available for download with impressive new visualizations. Download today from your account.
Has this been updated in the reporting system yet? Seems like it would be universally beneficial to have this built into the Telerik Reporting DLL
Getting an item at a given index from a collection is not supported via built-in expressions. You can create a custom function that returns the desired element. If you are using custom business objects, you can also extend them with functions performing the same logic - Work with raw data type's methods and properties.
Please feel free to log a feature request in Telerik Reporting feedback portal. Features are considered for implementation based on the demand for them.
Regards,
Stef
Telerik by Progress
Hi Stef,
Is there a way to have a user function return an object with properties rather than just a string? For example if i have a custom user function that calculates and parses a value i might want to return an object that has the following properties
Object.FormattedValue
Object.Error
Object.ErrorMessage
Object.SomeOtherProperty
is this possible?
Yes, the user function can return a custom object which properties will be accessible. Yet custom object cannot be reused in one expression without calling again the user function.
Instead you can use a data item like Table item and set its DataSource via binding to the result of the user function. Then the item will be able to display all properties of the data object.
More examples can be found in How to use the ReportItem.DataObject property in expressions.
Regards,
Stef
Telerik by Progress