IronPython Spotfire: Creating Hierarchy Column and moving associated Filter to TableGroup.Subgroup - filter

I am working on an IronPython script for TIBCO Spotfire to create a new hierarchy column and then move the filter associated with the hierarchy to a TableGroup.Subgroup.
In my script I am doing the following:
1. Retrieving the table group "Result Table Group"
2. Retrieving the data table "Result Table"
3. creating a new subgroup "Result hierarchy subgroup"
4. Looping through all filters in the table group and
- hiding the filter
- creating a hierarchy column for the filter-associated column
- try to move the filter to the subgroup
Here is the relevant part from the code:
filterPanel = Document.ActivePageReference.FilterPanel
# get the correct tableGroup
for tableGroup in filterPanel.TableGroups:
if tableGroup.Name == "Result Table Group":
resultTableGroup = tableGroup
# get the correct dataTable
for table in Document.Data.Tables:
if table.Name == "Result Table":
resultDataTable = table
# create new subgroup
hierarchyfilterGroup = resultTableGroup.AddNewSubGroup("Result hierarchy subgroup")
filterPanel.InteractiveSearchPattern = ""
for filterHandle in filterPanel.FiltersMatchingSearchPattern:
tableGroupFilterHandle = resultTableGroup.GetFilter(filterHandle.FilterReference.Name)
if tableGroupFilterHandle != None:
tableGroupFilterHandle.Visible = False # hide filter in table group
# create a new hiearchy column
hierarchyColName = tableGroupFitlerHandle.FilterReference.Name + " - process hierarchy"
hierarchyExpressions = List[str]()
hierarchyExpressions.Add("[" + tableGroupFitlerHandle.FilterReference.Name + "]")
hierarchyExpressions.Add("[Process]")
hierarchy = HierarchyDefinition(HierarchyNestingMode.Nested, hierarchyExpressions)
resultDataTable.Columns.AddHierarchyColumn(hierarchyColName, hierarchy)
# try to get the hierarchy associated filter
hieararchyFilterHandle = tableGroup.GetFilter(hierarchyColName)
if hiearchyFilterHandle != None:
hierarchyfilterGroup.Add(hierarchyFilter.FilterReference)
However, tableGroup.GetFilter(hierarchyColName) always returns None for the hiearchy columns. As a result of running the script, I get the hierarchy filters correctly and I also see the subgroup correctly, but the hierarchy filters are not sorted into the subgroup.
Here are some other things I have tried:
Searching the whole FilterPanel for the hiearachy filter
FilterPanel.InteractiveSearchPattern = hierarchyColName
for filterHandle in filterPanel.FiltersMatchingSearchPattern:
...
--> does not find any MatchingFilters
Refreshing the dataTable before trying to find the filter
resultDataTable.Refresh()
...
​​​​​​​--> has no effect on the result
Using a separate second loop after the first loop for moving the filters
Could you please help me moving the hierarchy filter to the newly created subgroup?
Thank you in advance!

Finally figured it out and leaving the answer in case someone else ever gets stuck in the same place.
filterPanel = Document.ActivePageReference.FilterPanel
# get the correct tableGroup
for tableGroup in filterPanel.TableGroups:
if tableGroup.Name == "Result Table Group":
resultTableGroup = tableGroup
# get the correct dataTable
for table in Document.Data.Tables:
if table.Name == "Result Table":
resultDataTable = table
# create new subgroup
hierarchyfilterGroup = resultTableGroup.AddNewSubGroup("Result hierarchy subgroup")
filterPanel.InteractiveSearchPattern = ""
for filterHandle in filterPanel.FiltersMatchingSearchPattern:
tableGroupFilterHandle = resultTableGroup.GetFilter(filterHandle.FilterReference.Name)
if tableGroupFilterHandle != None:
tableGroupFilterHandle.Visible = False # hide filter in table group
# create a new hiearchy column
hierarchyColName = tableGroupFitlerHandle.FilterReference.Name + " - process hierarchy"
hierarchyExpressions = List[str]()
hierarchyExpressions.Add("[" + tableGroupFitlerHandle.FilterReference.Name + "]")
hierarchyExpressions.Add("[Process]")
hierarchy = HierarchyDefinition(HierarchyNestingMode.Nested, hierarchyExpressions)
resultDataTable.Columns.AddHierarchyColumn(hierarchyColName, hierarchy)
colExists, hierarchyCol = resultDataTable.Columns.TryGetValue(hierarchyColName)
resultTableGroup.FilterCollectionReference.AddNewFilter(hierarchyCol)
# move the filter to the subgroup
hierarchyFilterHandle = resultTableGroup.GetFilter(hierarchyColName)
hierarchyFilterHandle.Visible = True
dynamicSubGroup.Add(hierarchyFilterHandle.FilterReference)

Related

Select an item by name instead of id in VBS

I have recorded a script on SAP that runs on CITRIX. Everything worked fine until some items were added to the window that the right item was selected to filter the columns. I guess the reason is that the proper item (e.g. MATART in the shown picture) moved down and it was not the same row, order etc.
I was wondering whether there is a way to select the item by its name instead of id?
This is the part of the script with the line that selects the items:
session.findById("wnd[0]/tbar[0]/okcd").text = "/nzm082"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[33]").press
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").currentCellRow = 1
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").selectedRows = "1"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").clickCurrentCell
session.findById("wnd[0]/tbar[1]/btn[45]").press
You could test the following.
for example:
...
session.findById("wnd[0]/tbar[1]/btn[33]").press
set myLayout = session.findById("wnd[1]/usr/cntlGRID/shellcont/shell")
Rows = myLayout.RowCount
For i = 0 to Rows - 1
myVariant = session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").getCellValue (i, "VARIANT")
if myVariant = "MTART" then
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").currentCellRow = i
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").clickCurrentCell
Exit For
end if
next
session.findById("wnd[0]/tbar[1]/btn[45]").press
...
Regards, ScriptMan

How to create a temporary column + when + order by with Criteria Builder

here is the sql statement I am trying to translate in jpa :
select
id,
act_invalidation_id,
last_modification_date,
title,
case when act_invalidation_id is null then 1 else 0 end as test
from act order by test, last_modification_date desc
The actual translation
Root<Act> act = query.from(Act.class);
builder.selectCase()
.when(builder.isNull(actRoot.get("actInvalidation")), 1)
.otherwise(0).as(Integer.class);
Expression<?> actInvalidationPath = actRoot.get("actInvalidation");
Order byInvalidationOrder = builder.asc(actInvalidationPath);
Path<Date> publicationDate = actRoot.get("metadata").get("publicationDate");
Order byLastModificationDate = builder.desc(publicationDate);
query.select(act).orderBy(byInvalidationOrder, byLastModificationDate);
entityManager.createQuery(query).getResultList();
I try to create a temporary column (named test) of Integer type and orderby this column, then orderby lastmodificationdate. The content of this new column is determined by the value of actInvalidation field.
In short: How to create a temp column with integer values, then order by this temp column in jpa ?
Thank you
I didn't test this but it should work like this:
Root<Act> act = query.from(Act.class);
Expression<?> test = builder.selectCase()
.when(builder.isNull(actRoot.get("actInvalidation")), 1)
.otherwise(0).as(Integer.class);
Expression<?> actInvalidationPath = actRoot.get("actInvalidation");
Order byInvalidationOrder = builder.asc(actInvalidationPath);
Path<Date> publicationDate = actRoot.get("metadata").get("publicationDate");
Order byLastModificationDate = builder.desc(publicationDate);
Order byTest = builder.asc(test);
query.select(act).orderBy(byTest, byInvalidationOrder, byLastModificationDate);
entityManager.createQuery(query).getResultList();

Both sql and python constraints are not working in odoo 9

I have been battling with this for a while. none of the two options are working neither were they giving errors. i commented the pythonic constrain method for you to see.
code snippet:
class house_development(models.Model):
_name = 'house.development'
_description = 'Development'
_inherit = ["mail.thread"]
name = fields.Char(string="Name", required=True, track_visibility='onchange')
description = fields.Text(string="Description", track_visibility='onchange')
# #api.one
# #api.constrains('name')
# def _identify_same_name(self):
# for record in self:
# if record.name in self:
# raise exceptions.ValidationError("There is another development/project with the same name: %s" % record.name)
_sql_constraints = [
('name_unique',
'UNIQUE(name)',
"There is another development/project with the same name"),
]
It should be like that,
#api.multi
#api.constrains('name')
def _identify_same_name(self):
for record in self:
obj = self.search([('name','=ilike',record.name),('id','!=',record.id)])
if obj:
raise exceptions.ValidationError("There is another development/project with the same name: %s" % record.name)
You need to search for the same name but not with the same id.
And for database unique constrains you may add like that.
_sql_constraints = [
('name_unique', 'unique(name)', 'There is another development/project with the same name!!!'),
]
Database constrains will not be added if there are duplicate name in
table. Sql constrains will apply only if the rule is not violated by
the existing data. I think in your case that's the point with Sql
constrains. And make sure for that you need to upgrade module. first
check duplicate records in database by firing that query.
Select name, count(*) from table_name
group by name
having count(*) > 1;
Available operators in domain in odoo Click to see more.

Update row in database using LINQ - object copied

var queryResult = this.kindergardenDataContext.Groups.Where(g => g.group_id == groupToAdd.group_id && g.group_enabled==true);
if (queryResult != null && queryResult.Count() != 0)
{
Group groupToEdit = queryResult.First();
groupToEdit.group_name = groupToAdd.group_name;
groupToEdit.group_create_date = groupToAdd.group_create_date;
groupToEdit.Kindergarden = groupToAdd.Kindergarden;
groupToEdit.GroupGuardian = groupToAdd.GroupGuardian;
groupToEdit.Room = groupToAdd.Room;
}
this.kindergardenDataContext.SubmitChanges();
Hi. Im beginner in LINQ. Here is ok, but foreigns key kindergarden, groupguardian, room has been duplicated in database (added new rows in database in kindergarden, groupguardian, room table). How can I set good reference to update row in group table.
Unless you retrieved groupToAdd.Kindergarden, groupToAdd.GroupGuardian, andgroupToAdd.Roomfromthis.kindergardenDataContext` or attached them with the right IDs set, that is the expected behviour. It doesn't know that you mean the same object instances that already resides in the database.

Multiple Counts within a single query

I want a list of counts for some of my data (count the number of open.closed tasks etc), I want to get all counts inside 1 query, so I am not sure what I do with my linq statement below...
_user is an object that returns info about the current loggedon user
_repo is am object that returns an IQueryable of whichever table I want to select
var counters = (from task in _repo.All<InstructionTask>()
where task.AssignedToCompanyID == _user.CompanyID || task.CompanyID == _user.CompanyID
join instructions in _repo.GetAllMyInstructions(_user) on task.InstructionID equals
instructions.InstructionID
group new {task, instructions}
by new
{
task
}
into g
select new
{
TotalEveryone = g.Count(),
TotalMine = g.Count(),
TotalOpen = g.Count(x => x.task.IsOpen),
TotalClosed = g.Count(c => !c.task.IsOpen)
}).SingleOrDefault();
Do I convert my object to single or default? The exception I am getting is, this sequence contains more than one element
Note: I want overall stats, not for each task, but for all tasks - not sure how to get that?
You need to dump everything into a single group, and use a regular Single. I am not sure if LINQ-to-SQL would be able to translate it correctly, but it's definitely worth a try.
var counters = (from task in _repo.All<InstructionTask>()
where task.AssignedToCompanyID == _user.CompanyID || task.CompanyID == _user.CompanyID
join instructions in _repo.GetAllMyInstructions(_user) on task.InstructionID == instructions.InstructionID
group task by 1 /* <<=== All tasks go into one group */ into g select new {
TotalEveryone = task.Count(),
TotalMine = task.Count(), // <<=== You probably need a condition here
TotalOpen = task.Count(x => x.task.IsOpen),
TotalClosed = task.Count(c => !c.task.IsOpen)
}).Single();
From MSDN
Returns the only element of a sequence, or a default value if the
sequence is empty; this method throws an exception if there is more
than one element in the sequence.
You need to use FirstOrDefault. SingleOrDefault is designed for collections that contains exactly 1 element (or none).

Resources