在 AX 2012 中获取分配给用户的安全角色的创建日期时间和创建者
To get the created datetime and created by for Security role assigned to user in AX 2012
是否有可能获得 CreatedDateTime 和 Createdby security role 通过 sql 查询添加到 user
这是用于获取安全角色的查询
select distinct a.id as username , a.NAME Name, f.Text [Role]
from userinfo a (nolock) join securityuserrole b (nolock) on a.id=b.user_
join SECURITYUSERROLECONDITION c (nolock) on b.recid = c.securityuserrole
join [Dynamics_STG_model].[dbo].[ModelSecurityRole] e (nolock) on e.rolehandle = b.securityrole
join [Dynamics_STG_model].[dbo].[ModelElementLabel] f (nolock) on e.LABELID = f.LabelId and e.LABELMODULE = f.Module and f.Language='en_us'
请帮我解决这个问题。
提前致谢!
您可以尝试将 database logging 用于 table SecurityUserRole
(系统 → 安全用户角色)。
我自己想出了答案:
Declare @StartDate datetime
Declare @EndDate datetime
Set @StartDate = '2015-07-07 01:31:38.000'
Set @EndDate = '2015-08-21 01:14:14.000'
Set @StartDate = convert(datetime, dateadd(hour, 7, @StartDate), 100)
Set @EndDate = convert(datetime, dateadd(hour, 7, @EndDate), 100)
select distinct a.NAME [User Name]
,b.USERNAME [Role Modified By]
,convert(datetime, dateadd(hour, -7, b.CREATEDDATETIME), 100) [Modified DateTime]
,case b.LOGTYPE
when 0 then 'Added'
when 1 then 'Removed'
end as Status
,d.Text Role
from USERINFO a (nolock)
join(
select (case when logtype = 0 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 16) AS varbinary(8000)), 2)
when logtype = 1 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 10) AS varbinary(8000)), 2)
end) AS UserNam
,USERNAME
,CREATEDDATETIME
,logtype
,(case when logtype = 0 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 15) AS varbinary(8000)), 2)
when logtype = 1 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 9) AS varbinary(8000)), 2)
end) as SecurityRole
from SYSDATABASELOG (nolock) where TABLE_=65492 and data !='') b
on a.id = b.UserNam
left outer join [DynamicsAX_model].[dbo].[modelsecurityrole] c (nolock) on b.SecurityRole =c.rolehandle
join [modelelementlabel] d (nolock) on c.labelid = d.labelid
and c.LABELMODULE = d.module
and d.Language='en_us'
where b.CREATEDDATETIME >= @StartDate and b.CREATEDDATETIME <=@EndDate order by [Modified DateTime] desc
Conpeek 和 consize 是我们需要从下面创建的两个函数 link 下载 ConPeek.sql and ConSize.sql
是否有可能获得 CreatedDateTime 和 Createdby security role 通过 sql 查询添加到 user
这是用于获取安全角色的查询
select distinct a.id as username , a.NAME Name, f.Text [Role]
from userinfo a (nolock) join securityuserrole b (nolock) on a.id=b.user_
join SECURITYUSERROLECONDITION c (nolock) on b.recid = c.securityuserrole
join [Dynamics_STG_model].[dbo].[ModelSecurityRole] e (nolock) on e.rolehandle = b.securityrole
join [Dynamics_STG_model].[dbo].[ModelElementLabel] f (nolock) on e.LABELID = f.LabelId and e.LABELMODULE = f.Module and f.Language='en_us'
请帮我解决这个问题。 提前致谢!
您可以尝试将 database logging 用于 table SecurityUserRole
(系统 → 安全用户角色)。
我自己想出了答案:
Declare @StartDate datetime
Declare @EndDate datetime
Set @StartDate = '2015-07-07 01:31:38.000'
Set @EndDate = '2015-08-21 01:14:14.000'
Set @StartDate = convert(datetime, dateadd(hour, 7, @StartDate), 100)
Set @EndDate = convert(datetime, dateadd(hour, 7, @EndDate), 100)
select distinct a.NAME [User Name]
,b.USERNAME [Role Modified By]
,convert(datetime, dateadd(hour, -7, b.CREATEDDATETIME), 100) [Modified DateTime]
,case b.LOGTYPE
when 0 then 'Added'
when 1 then 'Removed'
end as Status
,d.Text Role
from USERINFO a (nolock)
join(
select (case when logtype = 0 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 16) AS varbinary(8000)), 2)
when logtype = 1 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 10) AS varbinary(8000)), 2)
end) AS UserNam
,USERNAME
,CREATEDDATETIME
,logtype
,(case when logtype = 0 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 15) AS varbinary(8000)), 2)
when logtype = 1 then dbo.CONPEEK(CAST(dbo.CONPEEK(data, 9) AS varbinary(8000)), 2)
end) as SecurityRole
from SYSDATABASELOG (nolock) where TABLE_=65492 and data !='') b
on a.id = b.UserNam
left outer join [DynamicsAX_model].[dbo].[modelsecurityrole] c (nolock) on b.SecurityRole =c.rolehandle
join [modelelementlabel] d (nolock) on c.labelid = d.labelid
and c.LABELMODULE = d.module
and d.Language='en_us'
where b.CREATEDDATETIME >= @StartDate and b.CREATEDDATETIME <=@EndDate order by [Modified DateTime] desc
Conpeek 和 consize 是我们需要从下面创建的两个函数 link 下载 ConPeek.sql and ConSize.sql