Search code examples
datatablecrystal-reportscrystal-reports-xi

Loop in records in datatable at forumla field in crystal report


I have datatable attached to my Crystal Report with the following structure

TypeId
TypeName

I want to display TypeName in GroupHeaderSection based on condition

For example

if TypeId = 1 then display hans

if TypeId = 2 then display MNHS

I tried the following formula to display records from this datatable

WhilePrintingRecords;
Local NumberVar result := -1;
Local NumberVar i := 1;
Local StringVar inString := "";
While i <= 5 And result = -1 Do
(
  // inString := IIF({DTPMS_RptLocationTr.LocationTypeId} = 1,{DTPMS_RptLocationTr.LocationTypeName},"")

   If {DTPMS_RptLocationTr.LocationTypeId} = 5 Then
     inString := {DTPMS_RptLocationTr.LocationTypeName};
   i := i + 1;
);
inString

Any suggestion on how to solve this


Solution

  • I found how to solve my issue.

    First i changed the way records returned from database I returned the data like that

    Type1 | Type2 | Type3
    ======================
    hans  | MNHS  | nhues
    

    so now i can bind data directly from datatable to report header