This is a migrated thread and some comments may be shown as answers.

Prevent showing errors when 'Expression Contains Object Not Found'

3 Answers 119 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Amanda
Top achievements
Rank 1
Iron
Amanda asked on 16 Sep 2014, 09:37 PM
Howdy all!

So, my scenario: I have a standard form with data coming from an XML document supplied at run time.  This form has a lot of options on it, and not all of them are relevant all the time, so it's typical for not all XML nodes to be supplied.

For example, an employee can choose donate to charity as part of their paycheck.  When the XML is generated for this report, if they're not donating to the charity, it will not send over 'CharityAmount'.  With our old reporting program, if it didn't find a field, it just left the textbox blank, which is what we wanted.

However, if I put in Value property the expression '=CharityAmount', I now get a big ugly box telling me that 'The expression contains object 'CharityAmount' that is not defined in the current context'.

This is a great tool if I'm always expecting CharityAmount - but I'm not.  I tried '=ISNULL(CharityAmount,"")' as the expression, but that didn't work.  Is there a way to turn off the error messages, or at least just certain ones?  If not, is there another way of doing what I need (being flexible if something's not found) other than 'Ensure all XML nodes a report expects is supplied'?

Thanks all!

3 Answers, 1 is accepted

Sort by
0
Amanda
Top achievements
Rank 1
Iron
answered on 17 Sep 2014, 07:50 PM
I figured out a way around my issue, but if anyone as any other ideas, please let me know!

First, I found a way to loop through all the text boxes in my report.  Before I assign a data source to the report, I send over my XML chunk to a custom method, and compare all my '=(FieldNames)' to my chunk.  Any tag that's not in the current XML chunk, I change the value of the text box on the fly.
Public Sub checkXML(xmlChunk)
    Dim allTextBoxes As ReportItemBase() = Me.Items.Find(GetType(Telerik.Reporting.TextBox), True)
 
    If Not IsNothing(xmlChunk) Then
        For Each tb As Telerik.Reporting.TextBox In allTextBoxes
            If tb.Value.StartsWith("=") Then 'Only those text boxes that have been assigned an XML field need to be considered
                Dim xmlField As String
                xmlField = Mid(tb.Value, 2) 'To not have the = sign as part of the search
                If Not xmlChunk.Contains(xmlField) Then
                    tb.Value = ""
                End If
            End If
        Next
    End If
End Sub





0
Accepted
IvanY
Telerik team
answered on 19 Sep 2014, 01:35 PM
Hello Amanda,

Since you are using XML as your data source and you have not provided any additional information on how exactly you are using it we can advise you to wrap the XML using your own classes. You can use the ObjectDataSource and your classes as a data source for your reports. Then when you are creating a new object it will have all the fields - the ones for which the node is missing will be just null. In this case you will be able to successfully use ISNULL and even provide your users with custom message if needed.

Regards,
IvanY
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Amanda
Top achievements
Rank 1
Iron
answered on 19 Sep 2014, 01:45 PM
Oo, that's a good idea Ivan!  Thank you!
Tags
General Discussions
Asked by
Amanda
Top achievements
Rank 1
Iron
Answers by
Amanda
Top achievements
Rank 1
Iron
IvanY
Telerik team
Share this question
or