Error JSONQL filter comparing between two nodes

0

Hi, first of all, I am not an expert using Jasper and JSONQL.

I am trying to use it and I get some problems when I write an expression that I need.

The input JSON i have is this:

{
  "customer": {
                "id"  : "Customer_20200305-1623-53ln-RQZX-95hasMTLJWa4",
                "href": "http://customer-customer-service-care-cd-drop31.ilocpde22.corp.amdocs.com/customerManagement/v1/customer/Customer_20200305-1623-53ln-RQZX-95hasMTLJWa4",
                "name"        : "Amit4598",
                "status"      : "Active",
                "statusReason": "Reason4",
                "engagedParty": {
                                  "type"   : "PartyRef",
                                  "refType": "Individual",
                                  "id"     : "Individual_01101404-0555-442e-8882-aaa2a02205f6",
                                  "href"   : null,
                                  "name"   : "givenName645130 familyName610747"
                }
  },
  "individuals": [
                  {
                    "id"  : "Individual_01101404-0555-442e-8882-aaa2a02205f6",
                    "href": "http://party-individual-service-care-cd-drop31.ilocpde22.corp.amdocs.com/partyManagement/v1/individual/Individual_01101404-0555-442e-8882-aaa2a02205f6",
                    "givenName"         : "Rayko",
                    "middleName"        : "Stoyanov",
                    "familyName"        : "Pepelanov",
                    "formattedName"     : "Sr. Rayko Stoyanov Pepelanov",
                    "fullName"          : "givenName674627 middleName6042 familyName654554",
                    "preferredGivenName": "preferredGivenName",
                    "birthDate"         : "1980-08-18T12:16:47.447Z"
                  },
                  {
                    "id"  : "Individual_01101404-0555-442e-8882-aaa2a0220525",
                    "href": "http://party-individual-service-care-cd-drop31.ilocpde22.corp.amdocs.com/partyManagement/v1/individual/Individual_01101404-0555-442e-8882-aaa2a02205f6",
                    "givenName"         : "paco",
                    "middleName"        : "Stoyanov",
                    "familyName"        : "Pepelanov",
                    "formattedName"     : "Sr. Rayko Stoyanov Pepelanov",
                    "fullName".         : "givenName674627 middleName6042 familyName654554",
                    "preferredGivenName": "preferredGivenName",
                    "birthDate".        : "1980-08-18T12:16:47.447Z"
                  }
                 ]
}

What I need is to get the givenName json field from the individuals list whose id field has the same value as the id json field in customer.engagedParty.id.

So, I have this expression:

individuals.id(@val=="Individual_01101404-0555-442e-8882-aaa2a02205f6")^.givenName

It works, but it has the static value of the id, and I want to get it from customer.engagedParty.id dinamically.

I have tried with some expressions but it doesn't work:

individuals.id(@val==customer.engagedParty.id)^.givenName
 
individuals.id(@val==^^.customer.engagedParty.id)^.givenName
 
individuals.id(@val==^.^.customer.engagedParty.id)^.givenName
 
individuals.id(@val==$F{id})^.givenName    # being the id field the value of customer.engagedParty.id
 
individuals.id(@val==$P{id})^.givenName    # being the id parameter the value of customer.engagedParty.id
 
individuals.id(@val==$V{id})^.givenName    # being the id variable the value of customer.engagedParty.id

I don't know what to do. Please, could you help me to get the correct expression in order to get the id?

Thank you.

bmorata's picture
Joined: Apr 22 2020 - 8:35am
Last seen: 6 months 1 week ago

1 Answer:

0

If you are trying to filter inside a field expression, it is not possible. Filtering with values from the same JSON tree it is also not supported.

In your case you could filter in a subDataSource that you pass to a list like so:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.12.2.final using JasperReports Library version 6.12.2-75c5e90a222ab406e416cbf590a5397028a52de3  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="119c58db-8ae4-4c92-8cd2-16ea09ccb158">
    <subDataset name="IndividualsDS" uuid="639a0f17-766f-42f5-bdfe-4157c94becfe">
        <field name="givenName" class="java.lang.String">
            <property name="net.sf.jasperreports.jsonql.field.expression" value="givenName"/>
            <fieldDescription><![CDATA[givenName]]></fieldDescription>
        </field>
    </subDataset>
    <queryString language="jsonql">
        <![CDATA[customer]]>
    </queryString>
    <field name="customerId" class="java.lang.String">
        <property name="net.sf.jasperreports.jsonql.field.expression" value="id"/>
        <fieldDescription><![CDATA[id]]></fieldDescription>
    </field>
    <field name="customerName" class="java.lang.String">
        <property name="net.sf.jasperreports.jsonql.field.expression" value="name"/>
        <fieldDescription><![CDATA[name]]></fieldDescription>
    </field>
    <field name="customerEngagedPartyId" class="java.lang.String">
        <property name="net.sf.jasperreports.jsonql.field.expression" value="engagedParty.id"/>
        <fieldDescription><![CDATA[engagedPartyId]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <columnHeader>
        <band height="30" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="180" height="30" uuid="81411315-5690-4f34-a559-3f792e0aad89"/>
                <text><![CDATA[Customer Id]]></text>
            </staticText>
            <staticText>
                <reportElement x="180" y="0" width="185" height="30" uuid="1251081f-19ac-46cd-a22e-71159f586b76"/>
                <text><![CDATA[Customer Name]]></text>
            </staticText>
            <staticText>
                <reportElement x="365" y="0" width="185" height="30" uuid="b1e0c3a6-a04c-4bdd-99f3-f1a1e612a62c"/>
                <text><![CDATA[Individual Name]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="180" height="30" uuid="f6957d1f-1d6b-4855-8ced-af36ea456ff0"/>
                <textFieldExpression><![CDATA[$F{customerId}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="180" y="0" width="185" height="30" uuid="2d38c046-a00f-40a0-8750-fd5c0d59018d"/>
                <textFieldExpression><![CDATA[$F{customerName}]]></textFieldExpression>
            </textField>
            <componentElement>
                <reportElement x="365" y="0" width="185" height="30" uuid="9e0fdaa7-3cef-4e9c-97a7-715bf5ef499e"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                    <datasetRun subDataset="IndividualsDS" uuid="72b178d8-0026-4847-9760-ce82b0256e42">
                        <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("^.individuals.*(id == \"" + $F{customerEngagedPartyId} +  "\")")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="30" width="185">
                        <textField>
                            <reportElement x="0" y="0" width="185" height="30" uuid="ddd6c429-74ee-41ea-9914-f9ff4c44a8f3"/>
                            <textFieldExpression><![CDATA[$F{givenName}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </band>
    </detail>
</jasperReport>

narcism's picture
1265
Joined: Nov 22 2010 - 12:39am
Last seen: 1 day 14 hours ago
Feedback