Searching for notifications

Paul Watson (101 posts)
January 4, 2018 01:39 PM
Accepted Answer

I have a group containing ~20 jobs. I would like to search for all notification messages sent in steps and/or responses. How could I do that?

I see that Tools > "Find and Replace" > "Search Elsewhere" tab allows "Notification Recipients" to be searched. However, I want to find the notifications associated with jobs.

Bill Staff (599 posts)
January 5, 2018 01:04 PM
Accepted Answer

The Find tool can find you all the notifications that go to a particular person or have particular text in them, but it can't tell you where there are notifications. To find this information you can use a database query or an API script.

Here's an API script that you can run as described in this article. It will list all the notifications found in jobs under a specified group. You just need to plug in the target group name on line 7. Use empty string ("") to search all groups, or specify the group name ("My Group" or "My Group\Sub Group").

'if the adTempus server is on a different computer, replace . with the name
'for example,
'Dim ServerName as String = "remoteservername"
'Dim ServerName As String = "."

'name of the group to search in, or empty string to start at root group
Dim groupName As String=""

Sub Main
	Using session = Scheduler.Connect(ServerName, LoginAuthenticationType.Windows, "", "")
		Using context=session.NewDataContext()
			Dim group=context.GetJobGroup(groupName)
			If group IsNot Nothing Then
				SearchGroup(group)
			End If
		End Using
	End Using
End Sub

Sub SearchGroup(targetGroup As JobGroup)

	For Each job In targetGroup.GetJobs(ObjectFetchOptions.FullFetch, False)
		SearchJob(job)
	Next

	For Each childGroup In targetGroup.GetGroups(ObjectFetchOptions.FullFetch, False)
		SearchGroup(childGroup)
	Next
End Sub

Sub SearchJob(job As Job)
	For Each jobStep In job.Steps
		SearchJobStep(job.FullyQualifiedName,jobStep)
	Next

	SearchResponses(job.FullyQualifiedName,job.Responses)
End Sub

Sub SearchJobStep(parentName As String, jobStep As JobStep)
	Dim levelName=parentName & " : step " & JobStep.StepNumber
	If jobStep.Task.ClassID = ClassID.NotificationTask Then
		Console.WriteLine(levelName,jobStep.Responses)
	End If
	
	SearchResponses(levelName,jobStep.Responses)

End Sub

Sub SearchResponses(parentName As String, responses As IEnumerable(Of Response))
	For Each response In responses
		If HasNotification(response) Then
			Console.WriteLine(parentName & " : response " & response.GetDescription())
		End If
	Next
End Sub

Function HasNotification(response As Response) As Boolean
	For Each action In response.Actions
		If action.ClassID=ClassID.NotificationAction Then
			Return True
		End If
	Next
	Return False
End Function

 

Replies are disabled for this topic.