I have a column group on a datafield. I need to group only when there is a value in the field. Right now it groups on the NULL field too.
I have tried the following group expressin:
=Fields!ScaleName.Value <> "" OR Fields!ScaleName.Value <> Nothing
You can resolve this problem using a Group Filter (right click on group > Group Properties > Filters):
expression: =IsNothing(Fields!ScaleName.Value)
type: Boolean
operator: =
value: =False
Related
When I try to sort using the "case" by the field of the join table, the following error is returned:
PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY
expressions must appear in select list
<Table1>.includes(:difficulty_level).order(difficulty_level_priority('ASC'))
def difficulty_level_priority(direction)
"
CASE
WHEN difficulty_levels.name = 'first' THEN '1'
WHEN difficulty_levels.name = 'second' THEN '2'
WHEN difficulty_levels.name = 'third' THEN '3'
WHEN difficulty_levels.name = 'last' THEN '4'
END #{direction.upcase}"
end
But a simple sort by name works correctly. Like this:
<Table1>.includes(:difficulty_level).order('difficulty_levels.name ASC')
I tried pasting the select('"difficulty_levels".*') and group(< some columns>) after includes(). It did not help.
It looks like you are trying to sort by the field of the join table, but the field you are trying to sort by is not in the select list. You need to add the field you are trying to sort by to the select list.
Im trying to set the filter for one2many list showing based on the condition of many2one field.
model_a.py :
name = fields.Many2one('hr.employee')
keya = fields.Many2one('model.b')
num_a = fields.Monetary()
model_b.py:
name = fields.Many2one('hr.employee')
o_2_m = fields.One2many('model.a', 'keya', string='one2many list will be filter base on num_c')
value_c = fields.Many2one('model.c', string='Value of C', required= True)
model_c.py:
_rec_name = "code_c"
code_c = fields.Char('Code', required= True)
num_c = fields.Monetary()
By default, the one2many list will show all records if the user will not select record of value_c.
If the user selects record via value_c field which has created contains the value of num_c, the one2many list will be filtered for showing base on the value of num_c.
For Example: if the num_a in one2many field is: 15
Then when the user fills in num_c field is: 15 too
Then the one2many list just shows all the records which have the value: 15
That's the key condition for the filter of one2many list.
I'd tried with these codes in model_b.py :
#api.onchange('value_c')
def onchange_value_c(self):
for rec in self:
if rec.value_c and rec.o_2_m:
for line in rec.value_c:
find_c = self.env["model.c"].search([('num_c', '=', line.num_c)])
find_a = self.env["model.a"].search([('num_a', '=', line.num_a)])
#compare value of num_c with num_a
if find_c.num_c == find_a.num_a:
for abc in rec.o_2_m:
return {'domain': {'o_2_m': [('num_a','=', abc.find_a.id)]}}
But it still not works. It still shows all one2many list's records, after selecting the record of value_c and click on the "Add a line" link.
Please help!
Thank you!
Finally, I'd solved my requirement.
Using onchange function in model_b.py like this:
#api.onchange('value_c')
def onchange_get_value_c(self):
for rec in self:
if rec.value_c:
for line in rec.value_c:
find_c = self.env["model.c"].search([('num_c', '=', line.num_c)])
if find_c:
return {'domain': {'o_2_m': [('num_a','=', find_c.num_c)]}}
It works fine when the user selecting many2one 'value_c' field which has the value in field 'num_c', then when clicking on the "Add a line" link, it will show all records which have value in field 'num_a' match or equal to the value in field 'num_c'.
If the user selecting many2one 'value_c' field but not set the value for field 'num_c' or the value does not match or equal to the value in field 'num_a'. Then when clicking on the "Add a line" link, it will show nothing, and raise inform.
I would like to select Users that has group that has name in a given array or has null group.
This is my attempted query:
#Query("SELECT u FROM User u WHERE (u.group is null OR u.group.name IN :groups)")
Optional<Page<User>> findUsersByKeywordAndGroupIncludingNullGroup(Pageable pageable, #Param("groups") String... groups); but when I run I have an error in SQL syntax.
Therefore, is there a correct way to do this?
Thanks in advance.
Problem with your query is
If you will pass (null or empty) groups, then the resultant query will become
select * from users where users.group is null or users.group in ()
Thus results in Syntax Error near '('
You can do a hack using sPEL
#Query("SELECT U FROM User U " +
"WHERE U.group IS NULL " +
"OR (1=:#{ #groups == null || #groups.size() == 0 ? 1 : 0} OR U.group.name IN :#{#groups})")
List findUserWithoutGroupOrInGroup(#Param("groups") List<String> groups);
Here, I have used a proxy condition
1=:#{ #groups == null || #groups.size() == 0 ? 1 : 0}
Second part of this condition returns 1 if the parameter groups is null or empty, results in condition 1=1 being TRUE and thereby skipping U.group.name IN :#{#groups}
This approach is not a recommended one, and also not scalable.
In my opinion, you should fetch the Users without any Group and Users in given group separately. You can even fire there queries in parallel and control not to fire Users in given group if groups is empty.
I'm having two select lists:
P8_BUSINESSRULETYPE - which has a query to select all the businessruletypes
P8_OPERATOR - which has a query to select the operator based on the value of P8_BUSINESSRULETYPE
I'm having a dynamic action which has to hide the operator selectlist when P8_BUSINESSRULETYPE = 9 OR P8_BUSINESSRULETYPE = 10 OR P8_BUSINESSRULETYPE = 7
My dynamic action:
Event: change
Selectiontype :item(s)
Item(s): P8_BUSINESSRULETYPE
condition: is not null
true actions: hide items p8_OPERATOR
false actions: show items p8_operator
condition: PL/SQL Expression
:P8_BUSINESSRULETYPE = '10' OR :P8_BUSINESSRULETYPE = '7' OR :P8_BUSINESSRULETYPE = '9'
I hope someone will be able to tell me what's wrong with my dynamic action and why it's still always showing P8_OPERATOR.
Thank you very much,
Elvira
please guide, i am able to work with Dynamic Group by , but when selecting non agrigated fields , i get the following error
No property or field 'name' exists in type 'IGrouping`2'
var result311 = (IQueryable)gle1.temptable.Where(a => a.IsAllowed == false && a.Code == "r01");
var result = result311.GroupBy("new (name, FirstAmountOriginal, SecondAccounting)", "it")
.Select("new (it.name,Sum(FirstAmountOriginal) as FirstAmountOriginalx, Sum(SecondAccounting) as SecondAccountingx)");
Please guide
Firstly, you should not group by the fields you want to aggregate and secondly, the grouping creates a grouping Key consisting of the fields you group by (in this case one), so you must address this key afterwards:
var result = result311.GroupBy("new(name)", "it")
.Select(#"new (it.Key.name,
Sum(FirstAmountOriginal) as FirstAmountOriginalx,
Sum(SecondAccounting) as SecondAccountingx)");