Topic
  • 7 replies
  • Latest Post - ‏2015-09-01T15:53:27Z by max072014
max072014
max072014
299 Posts

Pinned topic How to wrap data in a field in BIRT report

‏2015-08-24T16:55:32Z |

Hi,

I would like to know how to wrap data for a field in BIRT report , the wrapping has been set to AUTO . I tried to use the below function in expression in data binding of that particular field

wrap(longStr,width){ length = longStr.length; if(length <= width) return longStr; return (longStr.substring(0, width) + "\n" + wrap(longStr.substring(width, length), width)); } wrap( dataSetRow["CATALOGCODE"], 10 );  however it did not work , the whole report appeared as blank. Please advise if any one has done wrapping on any field in BIRT reporting.

Attachments

  • jasonverly
    jasonverly
    236 Posts

    Re: How to wrap data in a field in BIRT report

    ‏2015-08-24T20:48:18Z  

    Have you tried adding the field as 'Dynamic Text' instead of putting in the raw data field? I've had better luck with property settings on Dynamic Text fields than the raw data fields. 

  • jasonverly
    jasonverly
    236 Posts

    Re: How to wrap data in a field in BIRT report

    ‏2015-08-24T21:57:08Z  

    Have you tried adding the field as 'Dynamic Text' instead of putting in the raw data field? I've had better luck with property settings on Dynamic Text fields than the raw data fields. 

    I took a 2nd look at what you're trying to do and I think the issue is in the javascript being used. These are the steps I took to get it to work for me:

    1. Create a new data element in the report.
    2. Make sure the data element is set to 'String'
    3. Give the data element a name.
    4. Click the 'fx' button to enter the javascript.
    5. Update the javascript shown below with the field you're trying to wrap (3rd line) and modify the length of wrapping (set to 15 in example below).
    6. Preview the report. The field will be wrapped to the setting in the javascript.
    function wrap(longStr,width)
    { length = longStr.length; if(length <= width) return longStr; return (longStr.substring(0, width) + "\n" + wrap(longStr.substring(width, length), width)); } 
    wrap( dataSetRow["description"], 15 );
    

     

  • max072014
    max072014
    299 Posts

    Re: How to wrap data in a field in BIRT report

    ‏2015-08-26T02:27:44Z  

    I took a 2nd look at what you're trying to do and I think the issue is in the javascript being used. These are the steps I took to get it to work for me:

    1. Create a new data element in the report.
    2. Make sure the data element is set to 'String'
    3. Give the data element a name.
    4. Click the 'fx' button to enter the javascript.
    5. Update the javascript shown below with the field you're trying to wrap (3rd line) and modify the length of wrapping (set to 15 in example below).
    6. Preview the report. The field will be wrapped to the setting in the javascript.
    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">function wrap(longStr,width) { length = longStr.length; if(length <= width) return longStr; return (longStr.substring(0, width) + "\n" + wrap(longStr.substring(width, length), width)); } wrap( dataSetRow["description"], 15 ); </pre>

     

    Hi,

    It did work , the mistake that I was doing was modifying the existing data element for that field and not creating a new one. Thanks a lot!

  • max072014
    max072014
    299 Posts

    Re: How to wrap data in a field in BIRT report

    ‏2015-08-26T09:54:42Z  

    Hi,

    Though this is working now based on Jason's reply however if there is no data in that field then report throws error. Is there any way to over come such issue?

  • jasonverly
    jasonverly
    236 Posts

    Re: How to wrap data in a field in BIRT report

    ‏2015-08-26T20:29:39Z  
    • max072014
    • ‏2015-08-26T09:54:42Z

    Hi,

    Though this is working now based on Jason's reply however if there is no data in that field then report throws error. Is there any way to over come such issue?

    Just add a null condition check on the data element:

    if (dataSetRow["description"]== null) { '' } 
    else {
            function wrap(longStr,width)
            { length = longStr.length; if(length <= width) return longStr; return (longStr.substring(0, width) 
            + "\n" + wrap(longStr.substring(width, length), width)); } 
            wrap( dataSetRow["description"], 15 );
    }
    

    So if the field is empty (null), BIRT will print an empty string. Otherwise the report will wrap the field as expected. 

  • jasonverly
    jasonverly
    236 Posts

    Re: How to wrap data in a field in BIRT report

    ‏2015-08-31T20:17:52Z  

    Did the updated javascript work for you?

  • max072014
    max072014
    299 Posts

    Re: How to wrap data in a field in BIRT report

    ‏2015-09-01T15:53:27Z  

    Did the updated javascript work for you?

    Hi Jason,

     

    yes it worked , Thanks a lot for your help!!