Page 1 of 1

Report with condition in a field.

Posted: Thu Mar 30, 2023 3:23 pm
by pedromiceli
Hello Friends, I have a report, in my report i have some columns one of them is the "STATUS" column, and there only two options on this column "FAILURE" or "OK".
My question is, there is a way to change the background of this field with a condition on the report pdf? for example: if "FAILURE" background red else background green?

Re: Report with condition in a field.

Posted: Fri Mar 31, 2023 5:33 am
by kev1n
You should be able to achieve conditional formatting this way:

http://wiki.nubuilder.net/index.php/Rep ... lder#Field

Re: Report with condition in a field.

Posted: Mon Apr 10, 2023 6:26 pm
by pedromiceli
kev1n wrote: Fri Mar 31, 2023 5:33 am You should be able to achieve conditional formatting this way:

http://wiki.nubuilder.net/index.php/Rep ... lder#Field
Hi Kev1n thanks for your help, i red the link but i couldnt understand how to do this.

Conditional formatting is available in nuBuilder for changing the background and font color of a Field Object.

By prefixing a value with 10 characters eg. '#B#66FF99|' will change the background color to #66FF99 (red).
By prefixing a value with 10 characters eg. '#F#FF0000|' will change the font color to #FF0000 (light green).
By prefixing a value with 20 characters eg. '#B#66FF99|#F#FF0000|' will change both font and background colors.

How do i prefix a value? In object Properties in the nuReport Designer?

Re: Report with condition in a field.

Posted: Mon Apr 10, 2023 7:02 pm
by kev1n
Either use a procedure as shown in the linked example or

1. Create an SQL with the SQL Builder like:
sql_builder.png

Code: Select all

SELECT
   if ( STATUS = 'OK', CONCAT('#B#F5B7B1|', STATUS), CONCAT('#B#D5F5E3|', STATUS )) as STATUS ,
   other_column_1,
   other_column_2
FROM
    your_table
The SQL query selects data from a table called "your_table" and returns three columns: "STATUS", "other_column_1", and "other_column_2". (change accordingly)
The value of the "STATUS" column is conditionally formatted based on the value of the "STATUS" field in the table.

If the "STATUS" field is equal to 'OK', the background color of the "STATUS" field will be set to #F5B7B1 (a light shade of red)
If the "STATUS" field is not equal to 'OK', the background color of the "STATUS" field will be set to #D5F5E3 (a light shade of green)

The formatting is achieved by concatenating the appropriate prefix and value to the value of the "STATUS" field using the CONCAT function. The resulting formatted value is then assigned to the "STATUS" column for display.

2. and in the Report Builder, use that nuSQL:
report_builder.png