Question

ESQ query to find role

Hi everyone!

How are you?

I hope you can help me

I want know if a user have associated a functional role in his organization role.

Example: User: "apaez", Organization Role : "Operador Arcor", Functional Role: "Operador Empresa"

The user "apaez" is asocciatted the "Operador Arcor" Organization Role and "Operador Arcor" Organization Role is associatted "Operador Empresa" Functional Role

The query that builds in SQLServer is the following:

SELECT * FROM SysUserInRole ur

  JOIN SysFuncRoleInOrgRole a ON ur.SysRoleId = a.OrgRoleId

  JOIN VwSysRole sr ON a.FuncRoleId = sr.Id

Where sr.Name = 'Operador Empresa'

AND ur.SysUserId = '20abeba5-5327-45aa-a5c2-07c41ac1fdf2'

 

How can I replicate it in ESQ (Client)?

King Regards,

Ezequiel!

 

 

Like 0

Like

2 comments

Maybe this example can help

	function getUserSaveRights(callback, renderTo, scope) {
		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);
				callback.call(scope, renderTo, isSysAdmin);
			}
		}, this);
	}

 

Federico,

Thanks for you help!

I was able to solve the query in the following way:

var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
						rootSchemaName: "SysUserInRole"
					});
esq.addColumn("[SysFuncRoleInOrgRole:OrgRole:SysRole].FuncRole.Name", "RolFuncionaAsociado");
 
var esqFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysUser.Id", userId);
var esqFilter2 = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "[SysFuncRoleInOrgRole:OrgRole:SysRole].FuncRole.Name", nombreRol);
esq.filters.add("esqFilter", esqFilter);
esq.filters.add("esqFilter2", esqFilter2);
esq.getEntityCollection(function (result) {
   if (!result.success || result.collection.collection.length == 0) {
		// error processing/logging, for example
		this.showInformationDialog("Data query error");
		return;
   }
   debugger;
   this.set(nombreRol, true);
   return;
}, this);

King Regards!

Ezequiel

Show all comments