Fields() function and deep object graphs

8 posts, 0 answers
  1. IT
    IT avatar
    41 posts
    Member since:
    Jan 2010

    Posted 26 Feb 2012 Link to this post

    I'm trying to use the Fields() function in the Groupings property of a report.

    It will work if I use a field that is at the base of my object graph. For example:-

    =Fields("Price")

    However if I try to use a field from deeper in the graph, the generated report is blank. For example:-

    =Fields("Supplier.Name")

    Both of the above fields work fine as bound fields in the report itself.

    Specifying the field directly in the Groupings parameter works as expected:-

    =Fields.Supplier.Name

    The reason I want to use the Fields function is that I am passing a parameter into the report so I can change the grouping from the page from which the report is run.

    Can anyone tell me if the Fields() method should work with deep mapped fields? or was this overlooked when deep object support was added in Q2 2007?

    Thanks in advance.
  2. Elian
    Admin
    Elian avatar
    435 posts

    Posted 29 Feb 2012 Link to this post

    Hello Aleks,

    Using the Fields() functions you get the actual data objects and not their string representation. If you say "Supplier.Name" the engine is looking for an object with that name.
    In order to get the supplier's name you need:
    =Fields("Supplier").Name because Fields("Supplier") is the Supplier object and you want to access its Name property.

    All the best,
    Elian
    the Telerik team
    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
  3. DevCraft banner
  4. IT
    IT avatar
    41 posts
    Member since:
    Jan 2010

    Posted 29 Feb 2012 Link to this post

    Elian,

     

    Thanks for your reply, however it doesn’t really answer my question.

     

    I was aware the Fields() function returns an object… that’s what I’m counting on. But it’s not what it returns that is the problem, it’s where it looks.

     

    As far as the engine looking for an object with the name “Supplier.Name”… that’s precisely what I want. Supplier.Name is an object (in this case  a string property on my Supplier object), which it appears the Fields() function is unable to resolve because it’s more than one level deep on the data record's object graph.

     

    So to my original question: prior to Q2 2007, specifying fields like =Fields.Supplier.Name didn’t work, because the engine could not evaluate a deep object graph on the data record. In Q2 2007 support for this was added to the Fields object, but not (it appears) to the Fields() function.

     

    If the Fields() function does work exactly the same way as the Fields object, then how do I achieve what I want as above? I want to pass the field itself to the Sorting (or Grouping) parameter by specifying a property on my data record via a string I pass in via a parameter.

     

    It appears the Fields() function was designed specifically for this purpose… to allow me to obtain a reference to a field (and not the value of the field) using a string representation of that field's name, so that I can pass that reference to some other function in the report.

     

    In your example:

     

    =Fields(“Supplier”).Name

     

    I can pass the “Supplier” as a parameter, but I cannot pass “Name”, so it would only work if I wanted to constrain my sorting to the Name property of the desired object (which won’t work).

     

    Perhaps I could call =Fields(“Supplier”).Fields(“Name”), however even if that did work (I haven’t tried) it wouldn’t solve the problem… I’m then restricted to grouping/sorting by properties that are exactly 2 levels deep in graph (this won’t work either)

     

    So for an example, if my object looks like this:-

     

    Order (the data source is a list of these)
        Id (int)
        Reference (string)
        Customer (customer object)
            Name (string)
            Country (string)
         Supplier (supplier object)
            Name (string)
            Country (string)

     

    How could I build a report with the ability to dynamically sort by one of these three fields:-

    • Reference
    • Supplier.Name
    • Customer.Country

     

  5. Elian
    Admin
    Elian avatar
    435 posts

    Posted 05 Mar 2012 Link to this post

    Hello Aleks,

    As you are already aware, the Fields() function does not dig deeper in the objects. The easiest solution would be to use IIF() nesting. Something like this:

    =IIF (parameter = 'Order.Customer.Name', Fields.Customer.Name,
                                IIF(parameter = ' ' ...
    Regards,
    Elian
    the Telerik team
    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
  6. Shawn Krivjansky
    Shawn Krivjansky avatar
    86 posts
    Member since:
    Jan 2010

    Posted 03 Sep 2012 Link to this post

    Man...  I am adding my vote to get this to work ASAP!

    I just can't believe Telerik can't get the Fields() function to accomodate this.
    I mean...  this is practically the same concept that we use on RadGrids when we declaritively assign a data field to a column.  If we want the field 3 layers up or down the chain, we just use "object1.object2.FieldName".  Somehow RadGrid knows what that "text" representation of a object/field combination should be.  I have to assume behind the scenes it is taking that "text" and figuring out the actual object/field from it...no matter how many layers it is.

    It takes the Fields() function from a great idea to practically useless (unless you are creating reports with only flat objects).  Telerik has a wonderful ORM.   Whether I choose to use the OpenAccessDataSource directly or use an ObjectDataSource against some ORM objects, there ARE going to be layers.  The minute I have any layers, the Fields() function pretty much can't ever be used, because at some point the needs of the report will be such that fields from the reference objects are needed and the Fields() function will blow up.  So, you are stuck designing a solution that can accomodate all fields (which means Fields() can't be used).

    Simple example...
    Since Telerik can't yet support any type of auto/user sorting on fields (or some out of the box mechinism for the user to chose which field(s) to sort by), I was coming up with my own solution based on this concept.  I wasn't doing it exactly like that, but similar principles.  I was creating my own function that returned the sorting values for a datasource used in a "sortby" parameter.  Those "values" were the "field names" that you would use if you wanted to sort the report normally.  So, in my sorting setup, I used something like:
    = Fields(Parameters.SortBy.Value)
    This works great!!!
    As long as my datasource pulls the "field names" (presented in a dropdown), that one sorting expression can accomodate an unlimited # of user sorts.
    However, this ONLY WORKS for the TOP level of fields!!
    If you reference ANY sub object, the Fields() function blows up.
    So, my one nice expression that should be able to handle anything is now useless.
    Instead???
    I have to list out 20 expressions...one for each possible sort... testing the "text/value" and assigning the field myself.
    Such a PITA!!
    So much so.... that I just say screw it.
    Totally not worth the effort when all this could be avoided if the Fields() function just did what it is supposed to do.

    If we aren't going to have out-of-box user/sortable functonality, can we PLEASE at least get the Fields() function working?
    Pretty sure Telerik could just copy/paste the code for how RadGrid or any of the other bindable objects handle it when a layered object is referenced as text.



  7. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Sep 2012 Link to this post

    Hi guys,

    You would be happy to know that in the next product version (respectively internal build) the Fields function would be able to evaluate a deep object graph.

    Thank you for the patience.

    Greetings,
    Steve
    the Telerik team

    BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

  8. Shawn Krivjansky
    Shawn Krivjansky avatar
    86 posts
    Member since:
    Jan 2010

    Posted 07 Sep 2012 Link to this post

    That is great news!

    You say in the next internal build.  Any idea what day it might be ready?
    Also, is there a date planned for the 2012 Q3 release yet (in case I wanted to wait until the full official release)?

    Thanks!
  9. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 12 Sep 2012 Link to this post

    Hi Shawn,

    The official Q3 2012 release is expected in mid-October. However, we will do our best to prepare an internal build in a couple of weeks.

    All the best,
    Peter
    the Telerik team

    BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Back to Top
DevCraft banner