Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple objects in JSON data source #312

Open
Karyang opened this issue Mar 22, 2022 · 0 comments
Open

Multiple objects in JSON data source #312

Karyang opened this issue Mar 22, 2022 · 0 comments

Comments

@Karyang
Copy link

Karyang commented Mar 22, 2022

Describe the bug
What's the correct way to access main and subs in Jasper Reports if there are multiple objects in JSON?

$extension = 'pdf' ;
$name = 'testeJasper';
$filename =  $name  . time();

$input = storage_path('app/public/relatorios/invoice.jasper');
$output = base_path('/public/reports/' . $filename);

$array = [
            [
              "category_id" => "1",
              "category_name" => "Module that will allow the pmmed to create a template first before cascading the PIs to offices from VP's OPCR"
            ],
            [
              "category_id" => "2",
              "category_name" => "Category 2"
            ],
            [
              "category_id" => "3",
              "category_name" => "Category 3"
            ]
        ];

$subReportSource = [
      ['program' => 'Higher', 'percentage' => '80%'],
      ['program' => 'Research', 'percentage' => '100%'],
    ];

$jsonArry = array('data' => ['main' => $array, 'subs' => $subReportSource ]);
$jsonTmpfilePath = storage_path('app/public'). '/relatorios/json/' . $name . '.json';
$jsonTmpfile = fopen($jsonTmpfilePath, 'w');
fwrite($jsonTmpfile, json_encode($jsonArry));
fclose($jsonTmpfile);
$datafile = $jsonTmpfilePath;

$options = [
        'format' => ['pdf'],
        'params' => [
          'msg' => "Display 101",
          'storage_path' => storage_path(),
        ],
        'locale' => 'en',
        'db_connection' => [
            'driver' => 'json',
            'data_file' => $datafile,
            'json_query' => 'data'
        ]
    ];

I tried to put this in my main.jrxml

<queryString language="json">
	<![CDATA[data.main]]>
</queryString>

and this one in my subReport.jrxml

<queryString language="json">
	<![CDATA[data.subs]]>
</queryString>

I just keep on getting this error
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant