Hi community!
How are you?
I hope you can help me with the following
I have a query with ESQ on "EmployeeMiniPage" to validate that the "NroLegajo" field in the Employee entity is not repeated. When I apply certain permissions on a record so that only certain users can see it, the query not consider that record when I log in with a user who does not have permissions, and therefore allows me to enter an existing "NroLegajo" that belongs to that record. To solve this I set the "QueryJoinRightLevel" system variable with value "2" (Disabled) but it does not work.
I reassigned and denied permissions on the registry to do the test and when I logged in with the user who does not have permissions on the registry I can continue entering a repeated value in the field "NroLegajo"
Any idea?
Is there an alternative a ESQ?
King Regards,
Ezequiel
Like
Dear Ezequiel,
In order to omit rights check you can create an ESQ on the server side by the means of C#. However, instead of using UserConnection, you can use SystemUserConnection, which would let you execute the functionality no matter under what user.
"Script task" business process element or service will perfectly fit and cover the task. Choose the means more comfortable for you.
Here is how to obtain SystemUserConnection:
private SystemUserConnection SystemUserConnection { get { return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection); }
Here is an article of how to build ESQ on server side. Though, its pretty much the same as on the client side:
https://academy.bpmonline.com/documents/technic-sdk/7-11/use-entitysche…
Hope you find it helpful.
Regards,
Anastasia
Hi Anastasia!
Thanks you for your answer!
How could I validate in the Employee registration that the "Legajo" field value is not repeated in the way you are indicating?
Can I call a business process from EmployeeMiniPage to return an answer?
I need that validation along with others before saving the employee!
King Regards!
Ezequiel
Dear Ezequiel,
In order to implement such functionality on the page, you need to do the following;
1. Create a webservice, which brushes through the Employee table for duplicates. Please see more details on how to write a service here:
https://academy.bpmonline.com/documents/technic-sdk/7-8/how-call-config…
2. Create a new virtual boolean attribute. We will use it in our further steps.
"ESQCompleted": { dataValueType: Terrasoft.DataValueType.BOOLEAN, type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN value: false }
3. Override a basic save() method and firstly insert a validation, that if this.get("ESQCompleted") true, than we call parent function, if not, than run service call, as in the article.
4. In the response, based on the result, you either show information dialog regarding existing duplicate, or set attribute to true and call save method again.
Regards,
Anastasia
Dear Anastasia,
Sorry, for the delay in the response. When working with the service I found several errors, I could not include the SystemUserConnection variable because it was throwing errors and when working with UserConnection as a test I also get several errors. Am i missing a reference?. I attach the code
namespace Terrasoft.Configuration.Test { using System; using System.ServiceModel; using System.ServiceModel.Web; using System.ServiceModel.Activation; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using Terrasoft.Common; using Terrasoft.Core; using Terrasoft.Core.DB; using Terrasoft.Core.Entities; // Service class is marked with [ServiceContract] compulsory attributes and // [AspNetCompatibilityRequirements] with parameters. [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public class EmployeeService { /*private SystemUserConnection SystemUserConnection { get { return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection); } }*/ // Service methods are marked with compulsory attributes [OperationContract] and [WebInvoke] with parameters. [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] public string ObtenerCantidadLegajosRepetidos(string nroLegajo, string cuitEmpresa) { //var result = nroLegajo + " + output string"; var result = "T"; entitySchemaManager = UserConnection.EntitySchemaManager; var employeeSchema = entitySchemaManager.GetInstanceByName("Employee"); var esqEmployee = new EntitySchemaQuery(entitySchemaManager, employeeSchema.Name); var colId = esqEmployee.AddColumn("Id"); //Agrego filtros en el query var filtroCUIT = esqEmployee.CreateFilterWithParameters(FilterComparisonType.Equal,"Account.UsrCUIT", cuitEmpresa); var filtroLegajo = esqEmployee.CreateFilterWithParameters(FilterComparisonType.Equal,"UsrNroLegajo", nroLegajo); // Adding created filters to query collection. esqEmployee.Filters.Add(filtroCUIT); esqEmployee.Filters.Add(filtroLegajo); // Execution of cache to database and getting resultant collections of objects. // Query results will be placed in cache after completion of this operation. var employeeCollection = esqEmployee.GetEntityCollection(UserConnection); if (employeeCollection == null || employeeCollection.Count == 0) { result = "F"; } return result; } } }
The errors that appear to me are the following:
I hope you can help me!
King Regards,
Ezequiel
Dear Ezequiel,
The reason for an error with UserConnection, is that you are missing "var" in variable declaration:
var entitySchemaManager = UserConnection.EntitySchemaManager;
As for the SystemUserConnection, please add the _systemUserConnection property declaration before the code I have previously indicated, like this:
private SystemUserConnection _systemUserConnection; private SystemUserConnection SystemUserConnection { get { return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection); } }
Hope this will solve the issue.
Regards,
Anastasia
Dear Anastasia!
How are you? Thank you for your answer!
Could it be that I'm missing a reference? I attached image
Regards!
Ezequiel
Dear Ezequiel,
Please try to make variable, which you assign SystemUserConnection, of a static type. In case this won't help, please share the whole code.
Regards,
Anastasia
Dear Anastasia,
I continue with the problem. I attached code.
namespace Terrasoft.Configuration.Test { using System; using System.ServiceModel; using System.ServiceModel.Web; using System.ServiceModel.Activation; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using Terrasoft.Common; using Terrasoft.Core; using Terrasoft.Core.DB; using Terrasoft.Core.Entities; [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public class EmployeeService { private static SystemUserConnection _systemUserConnection; private static SystemUserConnection SystemUserConnection { get { return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection); } } [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] public string ObtenerCantidadLegajosRepetidos(string nroLegajo, string cuitEmpresa) { //var result = nroLegajo + " + output string"; var result = "T"; var entitySchemaManager = SystemUserConnection.EntitySchemaManager; var employeeSchema = entitySchemaManager.GetInstanceByName("Employee"); var esqEmployee = new EntitySchemaQuery(entitySchemaManager, employeeSchema.Name); var colId = esqEmployee.AddColumn("Id"); var filtroCUIT = esqEmployee.CreateFilterWithParameters(FilterComparisonType.Equal,"Account.UsrCUIT", cuitEmpresa); var filtroLegajo = esqEmployee.CreateFilterWithParameters(FilterComparisonType.Equal,"UsrNroLegajo", nroLegajo); esqEmployee.Filters.Add(filtroCUIT); esqEmployee.Filters.Add(filtroLegajo); var employeeCollection = esqEmployee.GetEntityCollection(SystemUserConnection); if (employeeCollection == null || employeeCollection.Count == 0) { result = "F"; } return result; } } }
Thanks you for your help!
King Regards!
Dear Anastasia!
I have to say that removing the definition of SystemUserConnection and using UserConnection I get a similar error
King Regards!
Ezequiel
Dear Ezequiel,
Please find the modified code for your service. I have successfully tested it on my side:
namespace Terrasoft.Configuration.Test { using System; using System.ServiceModel; using System.ServiceModel.Web; using System.ServiceModel.Activation; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Web; using Terrasoft.Common; using Terrasoft.Core; using Terrasoft.Core.DB; using Terrasoft.Core.Entities; [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public class EmployeeService { [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] public string ObtenerCantidadLegajosRepetidos(string nroLegajo, string cuitEmpresa) { var appConnection = HttpContext.Current.Application["AppConnection"] as AppConnection; //var result = nroLegajo + " + output string"; var result = "T"; var entitySchemaManager = appConnection.SystemUserConnection.EntitySchemaManager; var employeeSchema = entitySchemaManager.GetInstanceByName("Employee"); var esqEmployee = new EntitySchemaQuery(entitySchemaManager, employeeSchema.Name); var colId = esqEmployee.AddColumn("Id"); var filtroCUIT = esqEmployee.CreateFilterWithParameters(FilterComparisonType.Equal,"Account.UsrCUIT", cuitEmpresa); var filtroLegajo = esqEmployee.CreateFilterWithParameters(FilterComparisonType.Equal,"UsrNroLegajo", nroLegajo); esqEmployee.Filters.Add(filtroCUIT); esqEmployee.Filters.Add(filtroLegajo); var employeeCollection = esqEmployee.GetEntityCollection(appConnection.SystemUserConnection); if (employeeCollection == null || employeeCollection.Count == 0) { result = "F"; } return result; } } }
Dear Andrey,
You have to use only UserConnection in GetEntityCollection method. Here is a signature of a method:
public EntityCollection GetEntityCollection(UserConnection userConnection)
Peter Vdovukhin,
Dear Peter,
Thank you for answer! May be you know how to get UserConnection on start appliacation (without users)?
Dear Andrey,
Could you create a new topic with this question? It will be available for search and may be helpful for others.
Could you try instead of:
var SysAdminUnitCollection = esqSysAdminUnit.GetEntityCollection(appConnection.SystemUserConnection)
write:
var SysAdminUnitCollection = esqSysAdminUnit.GetEntityCollection((SystemUserConnection)appConnection.SystemUserConnection) The thing is that SystemUserConnection inherits from UserConnection so you can pass SystemUserConnection instead of UserConnection