1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE [dbo].[Recipient_EnumerateVE] (
@Pending INT = 0,
@JobPrefixId INT = 101,
@JobId INT = 727,
@RecipientId INT = 0,
@FailedOnly INT = 0
)
AS
/* Description : Return list of recipients based on JobId and other supplied
* parameters. VENALI EXPRESS FLAVOUR
* In : @Pending - Return only recipients for jobs in a pending state
* @JobPrefixId - Identifier of gateway submitting job
* @JobId - Identifier of job whose recipients are to be returned
* @RecipientId - Identifier of recipient to return
* @FailedOnly - Return only those recipients with a completed
* status of failed.
* Out : Two recordsets:
* Summary Totals for job, listing successful, failed and
* pending recipients. Values returned are based only on
* the JobId and do not reflect effects of other parameters.
* Recipient List, return all recipients that meet the
* selection parameters provided.
* Notes : Based on the selection criteria, return the list of recipients for
* given job. Create summary totals are return those as well.
* History :
*
* Date Who Action Notes
* --------------------------------------------------------------------------
* 13/07/2011 MAS Created
*/
DECLARE @ReturnCode INT,
@RecordCount INT,
@JobSuccessCount INT,
@JobFailureCount INT,
@JobPendingCount INT,
@SystemJobId INT,
@MessageStringShort varchar(32),
@MessageStringLong varchar(128)
SET NOCOUNT ON
-- Logging: Start a System Job and log the SP parameters
SELECT @MessageStringShort = 'Recipient_EnumerateWork<' + convert(varchar, @JobPrefixId) + '-' + convert(varchar, @JobId) + '>'
EXEC @SystemJobId = [UTIL_BeginSystemJob]
@JobType = 3,
@JobTag = @MessageStringShort,
@OwnerJobPrefixId = @JobPrefixId,
@OwnerJobId = @JobId,
@OwnerRecipientId = @RecipientId
SELECT @MessageStringLong = 'Returning recipient list with the following parameters: @Pending = ' + convert(varchar, ISNULL(@Pending, 0)) + ', '
SELECT @MessageStringLong = @MessageStringLong + '@JobPrefixId = ' + convert(varchar, ISNULL(@JobPrefixId, 0)) + ', '
SELECT @MessageStringLong = @MessageStringLong + '@JobId = ' + convert(varchar, ISNULL(@JobId, 0)) + ', '
SELECT @MessageStringLong = @MessageStringLong + '@RecipientId = ' + convert(varchar, ISNULL(@RecipientId, 0)) + ', '
SELECT @MessageStringLong = @MessageStringLong + '@FailedOnly = ' + convert(varchar, ISNULL(@FailedOnly, 0))
EXEC [dbo].[UTIL_LogSystemJobDetail]
@JobId = @SystemJobId,
@JobDetail = @MessageStringLong
-- Create temporary table to hold the selected recipients
CREATE TABLE #RecptResultSet(JobPrefixId INT NOT NULL, JobId INT NOT NULL, RecipientId INT NOT NULL,
EventStatusId INT NOT NULL, EventDlvryECD VARCHAR(32) NULL, EventStopDt DATETIME NULL,
EventFaxNumber VARCHAR(32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , EventRecipientName NVARCHAR(64) NULL, EventRecipientCompanyName NVARCHAR(32) NULL,
EventDlvryAttempts SMALLINT NOT NULL, ErrorSource INT NULL, ErrorCode INT NULL,
ErrorClass INT NULL, ErrorExtra INT NULL, ErrorDesc VARCHAR(100) NULL, EventStatusDesc VARCHAR(100) NULL,
EventSubmitDt DATETIME, EventStartDt DATETIME, EventDuration smallint, EventDlvrySpeed VARCHAR(8),
DlvryServerRecptRecvCSID VARCHAR(39), PageCt int, CoverSubject NVARCHAR(128),UserField1 NVARCHAR(32),EventDlvryCurrentPageCt int,
RecipTitle nvarchar (32) NULL,RecipFirstName nvarchar (32) NULL,RecipLastName nvarchar (32) NULL,
RecipAddress1 nvarchar (55) NULL ,RecipAddress2 nvarchar (55) NULL ,RecipCity nvarchar (29) NULL,
RecipState nvarchar (19) NULL ,RecipZip nvarchar (19) NULL ,RecipCountry nvarchar (35) NULL , RecipVoice nvarchar (34) NULL,
RecipField1 nvarchar(32) NULL,
RecipField2 nvarchar(32) NULL, RecipField3 nvarchar(32) NULL, RecipField4 nvarchar(32) NULL, RecipField5 nvarchar(32) NULL,
RecipField6 nvarchar(32) NULL, RecipField7 nvarchar(32) NULL, RecipField8 nvarchar(32) NULL, RecipField9 nvarchar(32) NULL,
RecipField10 nvarchar(32) NULL, RecipField11 nvarchar(32) NULL, RecipField12 nvarchar(32) NULL,
SenderName nvarchar (64) NULL, SenderCompany nvarchar (34) NULL,SenderAddress1 nvarchar (55) NULL,
SenderAddress2 nvarchar (55) NULL,SenderCity nvarchar (29) NULL,SenderState nvarchar (19) NULL,SenderZip nvarchar (19) NULL,
SenderCountry nvarchar (35) NULL,SenderVoice nvarchar (34) NULL,SenderFax nvarchar (34) NULL,
EventFaxNumberCountryCode VARCHAR(8) NULL , EventFaxNumberCountryName VARCHAR(64) NULL ,
FailureBRIPErrorDesc VARCHAR(100) NULL, FailureBRIPErrorCode INT NULL,
FailureReportLongString VARCHAR(23) NULL,
FailureErrorEmailNotification VARCHAR(1000) NULL, FailureErrorWSResponse VARCHAR(1000) NULL
)
-- Initialise
SELECT @ReturnCode = 0,
@RecordCount = 0,
@JobSuccessCount = 0,
@JobFailureCount = 0,
@JobPendingCount = 0
-- Get completed as well as pending recipients
INSERT #RecptResultSet(JobPrefixId, JobId, RecipientId, EventStatusId, EventDlvryECD, EventStopDt, EventFaxNumber,
EventRecipientName, EventRecipientCompanyName, EventDlvryAttempts, ErrorSource, ErrorCode, ErrorClass,
ErrorExtra, ErrorDesc, EventStatusDesc, EventSubmitDt, EventStartDt, EventDuration, EventDlvrySpeed,
DlvryServerRecptRecvCSID, PageCt, CoverSubject, UserField1,EventDlvryCurrentPageCt,
RecipTitle,RecipFirstName,RecipLastName,RecipAddress1,RecipAddress2,RecipCity,
RecipState,RecipZip,RecipCountry,RecipVoice,
RecipField1,RecipField2,RecipField3,RecipField4,RecipField5,RecipField6,
RecipField7,RecipField8,RecipField9,RecipField10,RecipField11,RecipField12,
SenderName,SenderCompany,SenderAddress1,
SenderAddress2,SenderCity,SenderState,SenderZip,
SenderCountry,SenderVoice,SenderFax)
EXEC [dbo].[Recipient_EnumerateWorker] @Pending, @JobPrefixId, @JobId, @RecipientId, @FailedOnly,
@RecordCount OUTPUT, @JobSuccessCount OUTPUT, @JobFailureCount OUTPUT, @JobPendingCount OUTPUT
CREATE NONCLUSTERED INDEX [idx_RecipientJobId] ON #RecptResultSet
(
[JobPrefixId], [JobId], [RecipientId]
)
EXEC [dbo].[UTIL_LogSystemJobDetail]
@JobId = @SystemJobId,
@JobDetail = 'Adding EventFaxNumber details'
-- Get the friendly description of the event status
UPDATE r
SET EventFaxNumberCountryCode = '1',
EventFaxNumberCountryName = 'USA/Canada'
FROM #RecptResultSet r
WHERE LEFT(EventFaxNumber,1) = '1'
UPDATE r
SET EventFaxNumberCountryCode = idc.DialingCode,
EventFaxNumberCountryName = idc.CountryName
FROM #RecptResultSet r
INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 6
UPDATE r
SET EventFaxNumberCountryCode = idc.DialingCode,
EventFaxNumberCountryName = idc.CountryName
FROM #RecptResultSet r
INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 5
UPDATE r
SET EventFaxNumberCountryCode = idc.DialingCode,
EventFaxNumberCountryName = idc.CountryName
FROM #RecptResultSet r
INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 4
UPDATE r
SET EventFaxNumberCountryCode = idc.DialingCode,
EventFaxNumberCountryName = idc.CountryName
FROM #RecptResultSet r
INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 3
UPDATE r
SET EventFaxNumberCountryCode = idc.DialingCode,
EventFaxNumberCountryName = idc.CountryName
FROM #RecptResultSet r
INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 2
UPDATE r
SET EventFaxNumberCountryCode = idc.DialingCode,
EventFaxNumberCountryName = idc.CountryName
FROM #RecptResultSet r
INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 1
EXEC [dbo].[UTIL_LogSystemJobDetail]
@JobId = @SystemJobId,
@JobDetail = 'Added Failure details'
UPDATE r
SET FailureBRIPErrorDesc = 'Success',
FailureBRIPErrorCode = 0,
FailureReportLongString = 'Success'
FROM #RecptResultSet r
WHERE EventStatusId=1
UPDATE r
SET FailureBRIPErrorDesc = em.BRIPErrorDesc,
FailureBRIPErrorCode = em.BRIPErrorCode,
FailureReportLongString = em.ReportLongString,
FailureErrorEmailNotification = em.ErrorEmailNotification,
FailureErrorWSResponse = em.ErrorWSResponse
FROM #RecptResultSet r
INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
r.ErrorClass=em.ECDErrortype AND
r.ErrorCode=em.ECDErrorCode AND
r.ErrorExtra=em.ECDErrorExtra
WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
UPDATE r
SET FailureBRIPErrorDesc = em.BRIPErrorDesc,
FailureBRIPErrorCode = em.BRIPErrorCode,
FailureReportLongString = em.ReportLongString,
FailureErrorEmailNotification = em.ErrorEmailNotification,
FailureErrorWSResponse = em.ErrorWSResponse
FROM #RecptResultSet r
INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
r.ErrorClass=em.ECDErrortype AND
r.ErrorCode=em.ECDErrorCode AND
0=em.ECDErrorExtra
WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
UPDATE r
SET FailureBRIPErrorDesc = em.BRIPErrorDesc,
FailureBRIPErrorCode = em.BRIPErrorCode,
FailureReportLongString = em.ReportLongString,
FailureErrorEmailNotification = em.ErrorEmailNotification,
FailureErrorWSResponse = em.ErrorWSResponse
FROM #RecptResultSet r
INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
r.ErrorClass=em.ECDErrortype AND
0=em.ECDErrorCode AND
0=em.ECDErrorExtra
WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
UPDATE r
SET FailureBRIPErrorDesc = em.BRIPErrorDesc,
FailureBRIPErrorCode = em.BRIPErrorCode,
FailureReportLongString = em.ReportLongString,
FailureErrorEmailNotification = em.ErrorEmailNotification,
FailureErrorWSResponse = em.ErrorWSResponse
FROM #RecptResultSet r
INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
0=em.ECDErrortype AND
0=em.ECDErrorCode AND
0=em.ECDErrorExtra
WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
-- Return the summary totals for the Job
SELECT @RecordCount AS [RecordCount],
@JobSuccessCount AS [JobSuccessCount],
@JobFailureCount AS [JobFailureCount],
@JobPendingCount AS [JobPendingCount]
EXEC [dbo].[UTIL_LogSystemJobDetail]
@JobId = @SystemJobId,
@JobDetail = 'Returning recipient list'
-- Return the list of all recipients for the Job
SELECT *
FROM #RecptResultSet
ORDER BY JobPrefixId,
JobId,
RecipientId
EXEC [dbo].[UTIL_LogSystemJobDetail]
@JobId = @SystemJobId,
@JobDetail = 'Recipient list return complete'
-- Destroy temporary objects
DROP
TABLE #RecptResultSet
EXEC [dbo].[UTIL_EndSystemJob]
@JobId = @SystemJobId
SET NOCOUNT OFF
RETURN @ReturnCode
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
|