Hi,
How to define a section rule condition checking if the current user account is equal to a certain value ?
Thanks
Eric
Like
Dear Eric,
In case you are working with section wizard, you can apply a rule to the field and use the following condition check.
On the other hand, if you are planning to use ESQ for your purposes, here is a chunk of code to check in your ESQ.
var currentUser = Terrasoft.SysValue.CURRENT_USER.value; var sysAdmins = ConfigurationConstants.SysAdminUnit.Id.SysAdministrators; var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "SysUserInRole" }); esq.addColumn("SysRole"); esq.addColumn("SysUser"); esq.filters.add("SysUser", Terrasoft.createColumnFilterWithParameter( Terrasoft.ComparisonType.EQUAL, "SysUser", currentUser)); esq.filters.add("SysRole", Terrasoft.createColumnFilterWithParameter( Terrasoft.ComparisonType.EQUAL, "SysRole", sysAdmins)); esq.getEntityCollection(function(response) { if (response && response.success) { var result = response.collection; var isSysAdmin = (result.collection.length !== 0); scope.set("isSysAdmin", isSysAdmin); } scope.loadMenu(); }, this);
Hope this solves the issue.
Regards,
Anastasia
Anastasia Botezat,
I'm using section rule condition and i want to check if the currentuser ACCOUNT is equal to an existing account value.
Thanks
Dear Eric,
In such case there is no possibility to cover the task with only business rule. You have not mentioned the actions you want to execute based on the account, therefore, for an example let's take a field visibility. In the example I will apply visibility condition of the field based on current user account.
Firstly, we will be using other type of business rules, which are not created in the Section Wizard, but in the page schema. You need to go to the system Advanced settings. Find or create a replacing schema for your section page (e.g. OrderPageV2 ).
In the replacing schema add BINDPARAMETER business rule. See the article for more information and instructions:
https://academy.bpmonline.com/documents/technic-sdk/7-12/how-hide-edit-page-field-specific-condition
So, leftExpression will be indication a field or attribute I want to set visibility to. The rightExpression will be set to my custom attribute, which we will create further. This is a current user account value.
Create your custom attribute. It should look like this:
attributes: { "CurrentUserAccount": { "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN, "dataValueType": Terrasoft.DataValueType.TEXT, "value": '' } }
Now we need to set the attribute. Firstly, create an ESQ function to the SysAdminUnit object in order to obtain the contact of current user. In the callback of the ESQ write another one ESQ to Account object, which uses the received ContactId value to obtain AccountId. This is how to obtain current user id: Terrasoft.SysValue.CURRENT_USER.value;
Final step is to override the onEntityInitialized method to call ESQ function you created in previous step.
Here is a link to the academy on ESQ function:
https://academy.bpmonline.com/documents/technic-sdk/7-11/entityschemaqu…
Regards,
Anastasia Botezat