My
configuration is based on CMDBuild 2.4.3 & READY2USE 1.1.
Upon
login, a group is selected by the user.
This
group has been configured with an associated filter, which is set to select
Configuration item cards so that only those beginning with the prefix are
visible.
In order
to prevent cards being created that belong to other groups, I need a trigger to
prevent creation of the card if the prefix in the Configuration item’s Code
attribute does not match that of the current group (which was selected at
login).
How do I
access the group for the user's session in a trigger function?
How do I
get the filter text for the group within the trigger function?
unfortunately there is not a simple way to do what you ask in your first question.
In order to send the login group to a trigger you have to create a reference field towards the Role class with a CQL filter on the login group. You can read the login group from a CQL filter with the syntax {group:id}. If you choose the "preselect if unique" flag the field will automatically take the value of the login group.
Once you have the group on a field of the form you can send it to a trigger like all the other fields.
The text of the filter for the group is in the Grant table, in the PrivilegeFilter column.
Thank you for the reply, CMDBuild Team. Firstly, this is my post. It seems to have taken the poster as Bolduc by default from the creator of the forum, perhaps?
Regarding your reply, I'm a little bit unsure what I need to do to implement this.
Do I create an attribute (e.g. LoginGroup) on a Configuration item sub-class (e.g. Monitor), of type REFERENCE with filter {group:id} with the 'Preselect if unique' flag ticked? If so, what Domain do I specify to select the Role class?
just define a new domain from the "Groups" class to the superclass Configuration item. Then define a reference attribute on Configuration item based on that domain and configure the CQL filter.
I have tried various definitions for the CQL filter, but cannot get it to work. I've made the attribute that I've defined (LoginGroup) editable and unticked 'Preselect if unique' to try and determine what the filter is returning. The various combinations that I've tried either return all the active groups from the Role table or nothing. I guess that the 'Preselect if unique' (if active) will return nothing and fail to pre-populate the field unless there is a single result returned.
I have tried reducing this further whilst comparing what is returned from SQL queries on the server, but with little success.
I'm not that familiar with CQL filters.
One CQL filter that I tried:
from
Role where "Id" = {client:group.id} => returned all the active groups
In case this was not returning the group id, I tried specifying an actual Id:
from
Role where “Id” = 17244 => returned all the active groups again
will return just the login role of the current session.
For debugging purpose you can take a look to the "Network" tab of the browser and check the parameters of the jsonrpc call "getcardlist". Among its parameters you should find the filter.