Report SetData/GetData alternative

MirvanMirvan Member Posts: 7
edited 2015-03-09 in NAV Three Tier
I'm beginner in writing RDLC reports and I'm not sure if I understand all details of this awkward solution for transport data from "current" dataset line to page header or footer.
I made some trials with surprisingly simple result but I'm not sure if it will be functional in all cases.
Rewiew and comment ti please !
private shared SavedFields as object
public function SaveFields(fields as object) as boolean
  SavedFields=fields
  return true
end function
public function GetField(FieldName as string) as object
  return SavedFields(FieldName).value
end function
Calling is straightforward. Saving current line from hidden box:
=code.SaveFields(Fields)
and retrieving of field with name MyField:
=code.GetField("MyField")

Comments

  • MirvanMirvan Member Posts: 7
    Ok, I found one drawback in my solution:
    Function SaveFields saves reference to Fields object, not its contents and because report engine reuses this object during processing dataset lines, there is no option how to save contents of particular line from page or worse, there is no guarantee which dataset line will be there when calling GetField (usually from page header or footer).
    Better solution should be to copy or clone object contents (all fields), but it seems to be difficult or impossible.
    Do you have some idea ?
    Thanks
  • MirvanMirvan Member Posts: 7
    Finally, this method is definitely wrong. My doubts:
    Mirvan wrote:
    ... there is no guarantee which dataset line will be there when calling GetField ...
    are unfortunately valid - current contents of referred dataset row at the moment of calling GetField is not the same as last processed line in page.
  • lakshanvindanalakshanvindana Member Posts: 79
    The accuracy of this functions depend on where you used SetData (SaveField).
    For example you can check report 204 : Sales - Quote (Standard report).
    Earlier MS used to call this function in cell value, but now moved to Hidden property.
    If you call this function on group header (hidden cell), you can get accurate output to the report header.

    Alternative :
    There is a simple way without using Code functions.
    1. Keep the data fields in the table (in group header), which you need in report header
    Value : Fields!No_SalesHeader.Value
    Name : Number_SalesHeader
    Hidden : True
    make group header repeat in every page
    2. Refer above cell at the report header text object as : ReportItems!Number_SalesHeader.Value
    refer from the NAME of the cell (not from the VALUE of the cell)

    Good Luck !!!
    :thumbsup:
    Lakshan Kulawansa
    ERP Consultant - MS Dynamics NAV
    https://lk.linkedin.com/pub/lakshan-vindana-kulawansa/37/2a2/592
  • gerdhuebnergerdhuebner Member Posts: 155
    Indeed, it looks like that a dynamic access to the Fields or Parameters collection is still not possible. This drawback seems to last for over 10 years, already...
    jameskovacs.com/2005/08/04/digging-deep-into-reporting-services/
    This is mainly due to the fact, that Fields does not inherit basic methods from the Collection class (for what reason ever). So it is not possible to retrieve the field names from Fields. This inhibits the deep copy (cloning) of Fields to another public shared variable.
    You might take a look at this:
    https://massivedynamicsblog.wordpress.com/2015/11/15/getting-rid-of-setdata-and-getdata-in-rdlc-reports-of-ms-dynamics-nav/
Sign In or Register to comment.