How to hide/unhide data element in report based on user's language in BIRT.

Hi All, My report design has a grid with 6 rows and 2 columns in it. I have all the static text labels on the first column(translated into Different language using resource translation), second column has data item which comes from data source. What i want is the data source has 2 different fields which contains language specific information and other is English data.
For example, I have Name field on the Grid, when a person who runs report in French langugage. His name should be displayed in French. When english language is set. person's English name should appear. I have this information in 2 different fields in data source.

I can get the current language from reportcontext.GetLocale() function, but I don't know how to make the fields visible based on the language parameter.

Am using BIRT version 4.7.0

Any insights will be greatly appreciated.

Best Answer

  • Accepted Answer

    Thanks for sharing the report. See if this works better. Create a computed column in the data set. For the expression, enter the following:

    if(reportContext.getLocale() == "fr_FR"){
    row["Home_Address_Local_Script"]
    }else{
    row["Home_Address_Western_script"]
    }

    Replace the two address data elements with the computed column. Hopefully this will work better for you.

    Jeff F.
    Customer Support Engineer I
    OpenText

Answers

  • edited June 2018

    You can select an element on the report, go to the Visibility editor, and write an expression that controls when the element displays.

    Note: I didn't test the expression script shown in the screenshot.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • Hey Jeff, I tried to use this expression under visibility of the field which i want to control. But this doesn't hide the field from the Grid. Any ideas what's wrong with this.

    I have tried to run as HTML and also as web viewer but the field doesn't gets hidden.

    If ((reportContext.GetLocale()).value != "fr_FR")
    { true;
    Else
    false;
    }

  • The syntax is a little off. Try this:

    If ((reportContext.GetLocale()).value != "fr_FR")
    { true;
    } else {
    false;
    }

    Jeff F.
    Customer Support Engineer I
    OpenText
  • It gives the syntax error at the else line. Please see attached screenshot.

  • edited June 2018

    The I in "if" should be lower case. That's the only issue I see and it could be due to autocorrect.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • Thanks Jeff, issue was the open brace({) should be at the end of if statement. like below.
    Do you know is their other way to achieve similar using script. Currently, for this i need to place 2 data items(1 for French and other for english) on the grid(it looks very odd when someone in studio sees it) to control its Visibility

    If ((reportContext.GetLocale()).value != "fr_FR") {
    true
    }else{
    false
    }

  • Could you please post a screenshot illustrating the issue?

    Jeff F.
    Customer Support Engineer I
    OpenText
  • edited July 2018

    Here you go !
    First one is for French and the second data item for english language. I have the visibility condition to hide one of them based on the language using the above script.

    what i wanted here is to i place only 1 data field on the report. Using script, i want to dynamically populate that corresponding data item in that place based on the language. Am not sure how to achieve this

  • It sounds like the issue you are encountering is a formatting issue. You said "it looks odd" in Studio. I can't tell what is not being displayed properly from the screenshot of the design although it is useful to see the elements on the report. There might be a simple solution. I would need a sample report that I can run illustrating the issue in order to offer suggestions on how to fix the display.

    Alternatively, I have attached a sample report that shows how to dynamically add columns to a report. The table automatically shows the customernumber and customername columns and you can select additional columns from a parameter list to be displayed. There is code in the data set to dynamically modify the query and code in the table to add the columns. This method could be used instead of including both columns and hiding one of them.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • Here is the sample report design. as you would see that on the grid 1st row has 2 data items(1 for English - Home Address in Western Script, other for French - Home Address in Local Script) similarly for the name as well. What i wanted is that i will have only 1 data item for each row. For example, 1st row (Address - will have only 1 data item for english). Using script, i need to replace that english data item on the 2nd column 1st row in Grid to correct report item field which holds data for french at that position.

  • It worked like a charm when i used computed column. I hit the road block again when the user preference on their profile is set as Preferred Locale = French, and Preferred display language = "English". So when the report actually runs it displays the data in French for those fields which has computed column. Remaining data is all displayed in English. I tried to overwrite this by using default locale but it doesn't work. Any insights on where its going wrong?

Sign In or Register to comment.