Solved

Conditional layout with dynamic model

  • 21 March 2022
  • 9 replies
  • 109 views

Userlevel 2
Badge +4

Hi,

I have tables which have a is_deleted column. Now I want to make a clear distinction where is_deleted = 1. I can do this with conditional layout where the background color is specific color, but adding this for each table is very time consuming. 

fyi: My application is in Universal GUI.

Is this possible with the dynamic model? If so, how should I do this? Thanks

icon

Best answer by Mark Jongeling 21 March 2022, 14:19

View original

This topic has been closed for comments

9 replies

Userlevel 7
Badge +23

Yes you can!:

For example something like this - Strategy: Deleted:

-- Create new conditional layouts.:
-- The column 'is_deleted' must exist in the table.
-- Create one conditional layout for every editable column in the table.
insert into conditional_layout
(
project_id,
project_vrs_id,
tab_id,
conditional_layout_id,
col_id,
font_id,
background_color,
background_color_light,
background_color_dark,
generated_by_control_proc_id
)
select
t.project_id,
t.project_vrs_id,
t.tab_id,
'is_deleted',
'is_deleted',
null,
-2608610, --Red
-2608610, --Red
-2608610, --Red
@control_proc_id
from tab t
where t.project_id = @project_id
and t.project_vrs_id = @project_vrs_id
and exists(select 1
from col c2
where c2.project_id = t.project_id
and c2.project_vrs_id = t.project_vrs_id
and c2.tab_id = t.tab_id
and c2.col_id = 'is_deleted')

insert into conditional_layout_condition
(
project_id,
project_vrs_id,
tab_id,
conditional_layout_id,
col_id,
condition,
type_of_value,
value,
generated_by_control_proc_id
)
select
t.project_id,
t.project_vrs_id,
t.tab_id,
'is_deleted',
'is_deleted',
0,
0,
'1',
@control_proc_id
from tab t
where t.project_id = @project_id
and t.project_vrs_id = @project_vrs_id
and exists(select 1
from col c2
where c2.project_id = t.project_id
and c2.project_vrs_id = t.project_vrs_id
and c2.tab_id = t.tab_id
and c2.col_id = 'conditional_layout_code')

 

Userlevel 7
Badge +23

Had to change the color real quick to -2608610 and add background_color_light and dark specially for Universal GUI

Userlevel 2
Badge +4

In which format should the color be?

Userlevel 7
Badge +23

It's a bit of a strange method but the most easy way of getting the right color is by creating a temporary Conditional layout with the desired color, then querying the Software factory database to obtain the color value.

Code:

select * from conditional_layout where conditional_layout_id = '[something unique]'

 

Userlevel 7
Badge +23

HI,

You can use the following code to obtain the correct number to use in the Dynamic model code:

declare @colorToConvert VARCHAR(20) = '1FFFFF'
set @colorToConvert = '0X'+@colorToConvert
select -CONVERT(INT, CONVERT(VARBINARY, @colorToConvert, 1))

Input the color in Hex (without #), output is the negative number you can use in your code.

Userlevel 2
Badge +4

The code for the conditional layout did work!

But, I do have a error that comes when generating the definition. It says that the record already exist and duplicate is not applicable. 

I think this is because I generate the same version. But how can I make this possible? So I don’t need to upgrade to a newer version (just because it takes a lot of time for a complete version upgrade)?

Userlevel 7
Badge +23

With the Delete strategy, the Software Factory should delete all present objects that this Dynamic model code created. Can you confirm the Strategy is set to “Deleted”?

Otherwise you can add a "Not exists” clause to ensure no duplicate objects are created. This des come with the downside that any changes to this code will not be applied on already existing objects.

Userlevel 2
Badge +4

Just checked and is indeed Delete for Strategy.

This is what I have based on your code given above.
 

I added “insert_user” & “insert_date_time” to make this record unique, but does not seem to work

Userlevel 7
Badge +23

Are you using the "Execute control procedure” button? This button does not remove the generated objects; that only happens during the Generate definition process.

In that case it is more handy to add a “Not exists” clause or converting the code to use Merge statements and use the Fully managed strategy.

Example:

-- Merge conditional_layout
;with current_conditional_layout as
(
select *
from conditional_layout
where project_id = @project_id
and project_vrs_id = @project_vrs_id
and generated_by_control_proc_id = @control_proc_id
)
merge current_conditional_layout t
using (select t.project_id as project_id,
t.project_vrs_id as project_vrs_id,
t.tab_id as tab_id,
t.conditional_layout_id as conditional_layout_id,
[rest]
@control_proc_id as generated_by_control_proc_id
from tab t) s
on s.project_id = t.project_id
and s.project_vrs_id = t.project_vrs_id
and s.tab_id = t.tab_id
and s.conditional_layout_id = t.conditional_layout_id
when matched and (t.show_conditional_layout <> s.show_conditional_layout
or t.col_id <> s.col_id
or [rest of columns that might change]) then
update
set show_conditional_layout = s.show_conditional_layout,
col_id = s.col_id,
[more column]
when not matched by target then
insert
(
[columns]
)
values
(
s.project_id, -- project_id
s.project_vrs_id, -- project_vrs_id
[more columns]
)
when not matched by source then
delete;

Rest of columns can be obtained from the table in SQL Server 😀 Hope it helps!