How can I prevent "not defined in current context" error when accessing values from a JSON Webservice datasource.

1 Answer 140 Views
Binding Conditional Formatting DataSource JSON DataSource Object DataSource WebService Expressions Filtering Rendering Report Designer (standalone) Styling
Eric
Top achievements
Rank 1
Eric asked on 12 Jan 2022, 08:54 PM

I am calling a JSON Webservice that does not return a nested object if the values are null.

I am using the value of the nested object (Fields.Orders.Salesperon.Name) in a detail row of my report.

This results in an error for any rows with no salesperson: "The expression containt object 'Name' that is not defined in the current context".

Here's a sample of what's being returned from the webservice:

{
  "Orders": [
    {
      "OrderNumber": 1,
      "Salesperson: { "Name": "Joe Example" }
    },
    {
      "OrderNumber": 2,
      "Salesperson: {}
    }
}

OrderNumber 1 will print fine. The row for OrderNumber 2 will have an error box.

Screenshot from the actual report:

 

How can I prevent this? I've tried null checks, value binding, conditional formatting... but it all throws an error because it's trying to access the nonexistent "Name" field on a record.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 17 Jan 2022, 02:08 PM

Hello Eric,

Do you try to get the Salesperson object directly from the Orders array? In other words, is your expression the following:

= Fields.Orders.Salesperson.Name

If this is the case, I am afraid that this approach will not work. In order to display data from nested objects, you should bind the collection field, in this case, the Orders field, to a data item. Then, this data item will have access to that scope's that and you will be able to display the Name field of the Salesperson objects inside that data item(like list, for example). In my tests, there were no errors using this approach.

For more information, please see the How to Databind to Collection Properties KB article.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
Binding Conditional Formatting DataSource JSON DataSource Object DataSource WebService Expressions Filtering Rendering Report Designer (standalone) Styling
Asked by
Eric
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or