{"id":1632,"date":"2010-09-13T23:08:23","date_gmt":"2010-09-13T17:38:23","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1632"},"modified":"2010-09-13T23:08:23","modified_gmt":"2010-09-13T17:38:23","slug":"passing-optional-parameters-in-jasper-reports","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/","title":{"rendered":"Passing Optional Parameters in jasper reports"},"content":{"rendered":"<p>Hi Guys,<\/p>\n<p>In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper\u00a0 report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status value of the customer is passed the report should should be further refined to include only those customer which were added and had the same status value as passed, If the status is not provided it should be ignored in SQL query in jasper report. So, in this case the status was an optional parameter.<\/p>\n<p>The solution I found was pretty elegant. On searching over the net, I found that parameters with an ! (exclamation) mark are compiled before the query is executed. That is,<\/p>\n<pre lang=\"groovy\">\r\n$P!{status}\r\n<\/pre>\n<p>will be compiled before the query is executed. So, I passed the status from my code in to the jasper report. Now, to take care of the condition that it could be optional, I added a new parameter inside the jasper report, say &#8220;status_value&#8221;. such that, status_value had a default value expression (DFE) :<\/p>\n<pre lang=\"groovy\">\r\n\r\n($P{status}==\"\" ? \" and customer.status=' \"+ $P{status} + \" ' \" )\r\n<\/pre>\n<p>Now in the SQL query in jasper I wrote <\/p>\n<pre lang=\"SQL\" >\r\nselect * from customer where customer.start_date=$P{startDate} and customer.end_date=$P{endDate} \r\n$P!{status_value}\r\n<\/pre>\n<p>what it does is that status_value is compiled before the execution of query. So the  condition in the DFE of status_value checks whether we a receive a status from outside or not, If we do the condition will be appended in the query. Other wise it won&#8217;t be appended and we are done. :).<\/p>\n<p>With Regards<\/p>\n<p>Sachin Anand<br \/>\nsachin@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper\u00a0 report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":70,"footnotes":""},"categories":[1],"tags":[159,160,405],"class_list":["post-1632","post","type-post","status-publish","format-standard","hentry","category-technology","tag-jasper","tag-report","tag-optional-parameter-in-jasper"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Sachin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Passing Optional Parameters in jasper reports | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Passing Optional Parameters in jasper reports | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#article\",\"name\":\"Passing Optional Parameters in jasper reports | TO THE NEW Blog\",\"headline\":\"Passing Optional Parameters in jasper reports\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sachin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2010-09-13T23:08:23+05:30\",\"dateModified\":\"2010-09-13T23:08:23+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":5,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#webpage\"},\"articleSection\":\"Technology, Jasper, jasper report, optional parameter in jasper\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#listItem\",\"name\":\"Passing Optional Parameters in jasper reports\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#listItem\",\"position\":3,\"name\":\"Passing Optional Parameters in jasper reports\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sachin\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sachin\\\/\",\"name\":\"Sachin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d84b0b7a42bd13ad65b8a665e117addb0455be6b706c443a53526dc9d0e5af87?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Sachin\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/\",\"name\":\"Passing Optional Parameters in jasper reports | TO THE NEW Blog\",\"description\":\"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/passing-optional-parameters-in-jasper-reports\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sachin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sachin\\\/#author\"},\"datePublished\":\"2010-09-13T23:08:23+05:30\",\"dateModified\":\"2010-09-13T23:08:23+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Passing Optional Parameters in jasper reports | TO THE NEW Blog","description":"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status","canonical_url":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#article","name":"Passing Optional Parameters in jasper reports | TO THE NEW Blog","headline":"Passing Optional Parameters in jasper reports","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sachin\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2010-09-13T23:08:23+05:30","dateModified":"2010-09-13T23:08:23+05:30","inLanguage":"en-US","commentCount":5,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#webpage"},"articleSection":"Technology, Jasper, jasper report, optional parameter in jasper"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/www.tothenew.com\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#listItem","name":"Passing Optional Parameters in jasper reports"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#listItem","position":3,"name":"Passing Optional Parameters in jasper reports","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/sachin\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/sachin\/","name":"Sachin","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d84b0b7a42bd13ad65b8a665e117addb0455be6b706c443a53526dc9d0e5af87?s=96&d=mm&r=g","width":96,"height":96,"caption":"Sachin"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/","name":"Passing Optional Parameters in jasper reports | TO THE NEW Blog","description":"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sachin\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sachin\/#author"},"datePublished":"2010-09-13T23:08:23+05:30","dateModified":"2010-09-13T23:08:23+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Passing Optional Parameters in jasper reports | TO THE NEW Blog","og:description":"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status","og:url":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Passing Optional Parameters in jasper reports | TO THE NEW Blog","twitter:description":"Hi Guys, In one of my projects, While working with jasper reports, one of the requirement I faced was of passing optional parameter to the sql query in jasper report. For eg. I had to write a query to find all new customers which were added between two given dates and if an optional status","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"1632","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 12:58:40","updated":"2024-02-29 08:41:23","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tPassing Optional Parameters in jasper reports\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Technology","link":"https:\/\/www.tothenew.com\/blog\/category\/technology\/"},{"label":"Passing Optional Parameters in jasper reports","link":"https:\/\/www.tothenew.com\/blog\/passing-optional-parameters-in-jasper-reports\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1632"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1632\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}