SSRS Report Inconsistencies

So, here is one which has me baffled. Same report using Report Builder or SSRS Report page and GUID

or Print Preview to PDF

If you notice the Asterisk in the RB (Top Pic) version is present after the LBS, but not shown in the PDF Print Preview or Printed (tested already) version. Anyone care to offer suggestions or posit theories?

Code to produce Asterisk:

' SSRS Field Expression:
=IIF(Len(Code.sMissingWeightsPartNums(Parameters!TableGuid.Value,Fields!QuoteNum.Value))=0," LBS"," LBS*")
'SSRS Custom Code:
Public Shared ht As System.Collections.Hashtable = New System.Collections.Hashtable()

Public Function sMissingWeightsPartNums(guid as String, QuoteNum as String) as String
  Dim sKey As String
  sKey = guid & QuoteNum
  If ht.ContainsKey(sKey) Then
    Return ht(sKey)
  Else
    Return ""
  End If
End Function

Public Function isBadPartWeight(dWeight as Double, PartNum as String, guid as String, QuoteNum as String) as Boolean
  Dim sKey As String
  sKey = guid & QuoteNum
  If (dWeight <= 0) Then
    if ht.ContainsKey(sKey) Then
      ht(sKey) = ht(sKey) & ", " & PartNum
    Else 
      ht.Add(sKey, PartNum )
    End If
    Return True
  Else 
      Return False
  End If 
End Function 

Hoping someone has some insight to offer here???

Just as a sanity check, which I often need, I would have to force myself to temporarily make the True False values more unique and/or temporarily just change the asterisk to another character just to see:

' SSRS Field Expression:
=IIF(Len(Code.sMissingWeightsPartNums(Parameters!TableGuid.Value,Fields!QuoteNum.Value))=0," LBS"," SBLA")

Changed to " XLBS" and same thing output is " LBS"
for some reason when it creates the PDF version it is not finding the value. Not sure how else to check this?

Since sMissingWeightsPartNums returns string, maybe place him without the IIF directly into the output, just as a sanity check again?

Also, what happens if you select a different output type like Excel or CSV which picks up a different rendering?

I wondered about execution order and how that might affect the execution of Code when rendering. And I wondered where you have placed the output as far as the report sections.

After trying multiple versions of your suggestion(s), I ended up adding several other checks & found the variable was not always available?!? It’s like the report body does not see the outside (header/footer/page data) always when it renders out to a PDF. To my surprise, it seems a hidden field is not evaluated so the value is not visible to the Tablix, but will be if field is 0 height and not hidden! Very weird. Rendering bug IMO.

Thanks for looking @Michael_Ramsey!

I get accessible value in the Tablix area with once I added the useless IIf below just to trigger the missing weight PartNum string building function.
:exploding_head: :exploding_head: :exploding_head:

'Note: I found I can set separate textbox to 0 height and it will not show also.  But value works below. 
'New txtLineExtPartWeight expression since I am always showing these values: 
=IIF(Code.isBadPartWeight(Fields!PartNetWeight.Value,Fields!PartNum.Value,Parameters!TableGuid.Value),Fields!SellingExpectedQty.Value * Fields!PartNetWeight.Value,Fields!SellingExpectedQty.Value * Fields!PartNetWeight.Value)


'=========================

'Update Working Code:
Public Shared ht As System.Collections.Hashtable = System.Collections.Hashtable.Synchronized(New System.Collections.Hashtable())

Public Function sMissingWeightsPartNums(sKey as String) as String
  If ht.ContainsKey(sKey) Then
    Return ht(sKey)
  Else
    Return ""
  End If
End Function

Public Function isBadPartWeight(dWeight as Double, PartNum as String,sKey as String) as Boolean
  If (dWeight <= 0) Then
    if ht.ContainsKey(sKey) Then
      if InStr(ht(sKey),PartNum) <= 0  Then 
        ht(sKey) = ht(sKey) & ", " & PartNum
      End If
    Else 
      ht.Add(sKey, PartNum )
    End If
    Return True
  Else 
      Return False
  End If 
End Function 

Nice!
That’s a nice trick to know regarding Hidden objects and their values. Thanks for that.

1 Like

I read about the page rendering is SSRS when I was trying to do something custom with page numbers.
If I remember, page numbers aren’t assigned until after each page for the entire report is rendered. Why you can’t do too much with the page numbers.
I have also learned not to rely on previews from within Report Builder, where page rendering is not exactly the same as regular printing. i.e. variables can appear to work but…

Ya, I would not have thought or realized this unless I had actually tested/produced validated outputs for this. Tried to include my thoughts in code above as it does not seem to preform as one would think.

Glad to have provided some info that might not have been apparent without a bit of extra research. :slight_smile:

I would not have thought this would be the case. The variables seem to be unset/inaccessible if created/caluclated in a hidden field in the same scope. Being available outside and in a global, but in need of being present in a visible field at a higher detail level if confusing when the hashtable (ht) variable is global to the FORM. If you don’t find this counterintuitive please explain to me :slight_smile: so I might understand the ‘why?’ behind it.

No, SSRS is NOT what I’d call intuitive.
And even more disturbing (for me) is that Report Builder gives the impression of being WYSIYG but it is definitely not.
SSRS is everywhere now, just have to work with it, but I’ve always preferred Crystal.

True but RDLs are just XML files so if you need fine control, you can edit positions in VSCode or a text editor of your choice. You can use Git as well this way so you can always revert to a previous version. I wouldn’t write a report from scratch this way but for layouts or finding hidden elements, it’s pretty good.

1 Like

Thanks for the info, I haven’t actually looked over the rdl file yet this is great info :smiley: :beers:

I realized this when I do view via RB, I get 2-3 page report where PDF render is 4-5, so I knew this but the fact that I get different resultant outputs for PDF vs RB instant render is crazy. I showed the missing public variable and after much testing I found simple fix was to make a embedded function call or use a 0 height VISIBLE field either worked. Hidden field did not show accurate variable value during a PDF render, but a RB instant did which is just crazy to me.

Yeah, I’ve come to believe that MS SQL (and many other software companies) look at the reporting tools as their “red headed stepchild”. They have to provide “something” in their product but it’s not where their hearts lie. I remember more than one developer telling me “I don’t do reports” over the years. Those of us at the end of the food chain who are then asked to create reports just have to learn to work the tools at hand and deal with any “weirdness” in them. i.e. I like to complain but… I don’t really expect tools to get too much better than it is now.