{"id":2104,"date":"2012-08-27T04:09:50","date_gmt":"2012-08-27T04:09:50","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=2104"},"modified":"2012-08-27T06:09:04","modified_gmt":"2012-08-27T06:09:04","slug":"addition-to-my-basic-requests-archiving-archiving-approval-info","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/addition-to-my-basic-requests-archiving-archiving-approval-info","title":{"rendered":"Addition to my basic Requests archiving &#8211; archiving Approval info"},"content":{"rendered":"<p>A long time ago now I posted a <a href=\"https:\/\/www.wapshere.com\/missmiis\/a-basic-requests-reporting-method\">basic SQL method of archiving the Requests history<\/a> to another database. I&#8217;m still using this with FIM 2010 and have updated the method now to also grab info about Approvals.<\/p>\n<p>Note I haven&#8217;t tested this with R2.<\/p>\n<p><!--more--><\/p>\n<h3>Create the tables<\/h3>\n<p>I\u00c2\u00a0have a database called &#8220;FIMReporting&#8221; in which I create the following two tables:<\/p>\n<pre>CREATE TABLE [dbo].[fim_approvals_new](\r\n\t[ObjectKey] [nvarchar](50) NULL,\r\n\t[Attribute] [nvarchar](50) NULL,\r\n\t[Value] [nvarchar](max) NULL\r\n) ON [PRIMARY]<\/pre>\n<p>&nbsp;<\/p>\n<pre>CREATE TABLE [dbo].[fim_approvals_log](\r\n\t[ObjectKey] [nvarchar](150) NULL,\r\n\t[Creator] [nvarchar](150) NULL,\r\n\t[CreatedTime] [nvarchar](150) NULL,\r\n\t[Request] [nvarchar](150) NULL,\r\n\t[Decision] [nvarchar](50) NULL,\r\n\t[Reason] [nvarchar](max) NULL\r\n) ON [PRIMARY]<\/pre>\n<h3>Extract Unarchived Approvals<\/h3>\n<p>The following script updates the fim_approvals_log table with info about Approvals that don&#8217;t yet appear in that table.<\/p>\n<pre>truncate table FIMReporting.dbo.fim_approvals_new;\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect o.ObjectKey, 'ObjectKey' as Attribute, o.ObjectKey as Value\r\nfrom FIMService.fim.Objects o\r\nleft outer join dbo.fim_requests_log l\r\non o.ObjectKey = l.ObjectKey\r\ninner join FIMService.fim.ObjectValueString s\r\non o.ObjectKey = s.ObjectKey\r\nwhere (o.ObjectTypeKey = 2 or o.ObjectTypeKey = 3)\r\nand l.ObjectKey is null\r\nand s.AttributeKey = 66;\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect v.ObjectKey, a.Name as Attribute, CAST(v.ValueBoolean as nvarchar) as Value\r\nfrom FIMService.fim.ObjectValueBoolean v\r\njoin FIMService.fim.AttributeInternal a\r\non v.AttributeKey = a.[Key]\r\njoin FIMReporting.dbo.fim_approvals_new n\r\non v.ObjectKey = n.ObjectKey\r\nwhere n.Attribute = 'ObjectKey';\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect v.ObjectKey, a.Name as Attribute, CAST(v.ValueDateTime as nvarchar) as Value\r\nfrom FIMService.fim.ObjectValueDateTime v\r\njoin FIMService.fim.AttributeInternal a\r\non v.AttributeKey = a.[Key]\r\njoin FIMReporting.dbo.fim_approvals_new n\r\non v.ObjectKey = n.ObjectKey\r\nwhere n.Attribute = 'ObjectKey';\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect v.ObjectKey, a.Name as Attribute, CAST(ValueInteger as nvarchar) as Value\r\nfrom FIMService.fim.ObjectValueInteger v\r\njoin FIMService.fim.AttributeInternal a\r\non v.AttributeKey = a.[Key]\r\njoin FIMReporting.dbo.fim_approvals_new n\r\non v.ObjectKey = n.ObjectKey\r\nwhere n.Attribute = 'ObjectKey';\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect v.ObjectKey, a.Name + 'DisplayName' as Attribute, name.ValueString as Value\r\nfrom FIMService.fim.ObjectValueReference v\r\njoin FIMService.fim.AttributeInternal a\r\non v.AttributeKey = a.[Key]\r\njoin FIMReporting.dbo.fim_approvals_new n\r\non v.ObjectKey = n.ObjectKey\r\njoin FIMService.fim.Objects ref\r\non v.ValueReference = ref.ObjectKey\r\njoin FIMService.fim.ObjectValueString name\r\non ref.ObjectKey = name.ObjectKey\r\nwhere n.Attribute = 'ObjectKey'\r\nand name.AttributeKey = 66;\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect v.ObjectKey, Name as Attribute, ValueReference as Value\r\nfrom FIMService.fim.ObjectValueReference v\r\njoin FIMService.fim.AttributeInternal a\r\non v.AttributeKey = a.[Key]\r\njoin FIMReporting.dbo.fim_approvals_new n\r\non v.ObjectKey = n.ObjectKey\r\nwhere n.Attribute = 'ObjectKey';\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect v.ObjectKey, Name as Attribute, ValueString as Value\r\nfrom FIMService.fim.ObjectValueString v\r\njoin FIMService.fim.AttributeInternal a\r\non v.AttributeKey = a.[Key]\r\njoin FIMReporting.dbo.fim_approvals_new n\r\non v.ObjectKey = n.ObjectKey\r\nwhere n.Attribute = 'ObjectKey';\r\n\r\ninsert into FIMReporting.dbo.fim_approvals_new\r\nselect v.ObjectKey, Name as Attribute, ValueText as Value\r\n from FIMService.fim.ObjectValueText v\r\njoin FIMService.fim.AttributeInternal a\r\non v.AttributeKey = a.[Key]\r\njoin FIMReporting.dbo.fim_approvals_new n\r\non v.ObjectKey = n.ObjectKey\r\nwhere n.Attribute = 'ObjectKey';\r\n\r\ninsert into dbo.fim_approvals_log (ObjectKey)\r\n\tSELECT n.ObjectKey from dbo.fim_approvals_new n\r\n\tleft outer join dbo.fim_approvals_log l\r\n\ton n.ObjectKey = l.ObjectKey\r\n\twhere n.Attribute = 'ObjectType'\r\n\tand n.Value = 'ApprovalResponse'\r\n\tand l.ObjectKey is NULL;\r\n\r\nupdate dbo.fim_approvals_log\r\nset Creator = Value\r\nfrom dbo.fim_approvals_log l\r\njoin dbo.fim_approvals_new n\r\non l.ObjectKey = n.ObjectKey\r\nand n.Attribute = 'CreatorDisplayName';\r\n\r\nupdate dbo.fim_approvals_log\r\nset CreatedTime = Value\r\nfrom dbo.fim_approvals_log l\r\njoin dbo.fim_approvals_new n\r\non l.ObjectKey = n.ObjectKey\r\nand n.Attribute = 'CreatedTime';\r\n\r\nupdate dbo.fim_approvals_log\r\nset Request = ap.Value\r\nfrom dbo.fim_approvals_log l\r\njoin dbo.fim_approvals_new ar\r\non ar.ObjectKey = l.ObjectKey\r\njoin dbo.fim_approvals_new ap\r\non ar.Value = ap.ObjectKey\r\nand ar.Attribute = 'Approval'\r\nand ap.Attribute = 'Request';\r\n\r\nupdate dbo.fim_approvals_log\r\nset Decision = Value\r\nfrom dbo.fim_approvals_log l\r\njoin dbo.fim_approvals_new n\r\non l.ObjectKey = n.ObjectKey\r\nand n.Attribute = 'Decision';\r\n\r\nupdate dbo.fim_approvals_log\r\nset Reason = Value\r\nfrom dbo.fim_approvals_log l\r\njoin dbo.fim_approvals_new n\r\non l.ObjectKey = n.ObjectKey\r\nand n.Attribute = 'Reason';<\/pre>\n<h3>Reporting<\/h3>\n<p>The fim_approvals_log table lists the approval details against the internal ObjectKey of the associated Request object. This makes it very easy to join to the fim_requests_log table to get a combined view of the request along with its approval.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A long time ago now I posted a basic SQL method of archiving the Requests history to another database. I&#8217;m still using this with FIM 2010 and have updated the method now to also grab info about Approvals. Note I haven&#8217;t tested this with R2.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[42,9,61,5],"tags":[],"class_list":["post-2104","post","type-post","status-publish","format-standard","hentry","category-fim-2010","category-logs","category-reporting","category-sql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-xW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/2104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=2104"}],"version-history":[{"count":5,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/2104\/revisions"}],"predecessor-version":[{"id":2113,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/2104\/revisions\/2113"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=2104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=2104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=2104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}