PDA

View Full Version : Scripting


mcjmdp
August 16th, 2005, 06:23 PM
We recently purchased MDP and we would like to write a script that will parse the file name of a report deposited on the MDP server and select the model, output disposition (email or file copy), and output location (user id). For example, zop0040_lmcclain_E.txt would imply we want to use model "zop0040" against this report text file and "E" implies we want to email it to user "lmcclain". Can this be done with scripting? Any and all thoughts and comments appreciated!
Thanks!

Gareth Horton
August 18th, 2005, 08:37 AM
Hi

The problem I can see is with the dynamic selection of the model and the relating choice of what you want to export (table, summary, filters, sorts etc) and where it should initially go.

The best approach would be to set up processes and projects that contain the relevant models, then use the file name with the necessary wildcards(i.e zop0040*.*) in the project to make sure the right model/project is applied to the input file.

You can then create a dynamic e-mail distribution by parsing out the necessary pieces of the filename.

You need to do this in the post-export script section.

I have some code to get you started. You will have to add the Microsoft.VisualBasic namespace to your imports.

Dim itemList As JobLogItemList
Dim item As JobLogItem
Dim n As Integer
Dim Filename as String
Dim Text() as String
dim Username as String
dim DistributionMethod as String

'create an itemlist. The ProjectID is automatically passed.
itemList = Log.GetInputItems(ProjectID)


' Check that input items exist
If itemList.Count = 0 Then

Log.AddEvent("No Input Items Exist")

Else
n = 0

'initialize the counter

For Each item In itemList
n = n + 1 'update the counter

'Get the full input filename
'Note that we are expecting c:...zop0040_lmcclain_E.prn
Filename = item.location


'Split the file on the underscore
'note the c to cast to char

text = Filename.split("_"c)

'get the second part of the array
Username = text(1)

Username = Username + "@datawatch.com"

Log.AddEvent("Username is: " + Username)

'get the third part of the array
DistributionMethod = text(2)

Log.AddEvent("Distribution Method is: " + DistributionMethod)

if DistributionMethod = "E.prn" then

Log.AddDistribution_Email(Filename,Username,"datap ump@datapump.com","","Subject","Body", True)

End If
Next
End If
Note another problem is that this can only work if you can easily derive an e-mail address from the username. In this case, I have just appended datawatch.com.

I hope this helps.

Gareth
Originally posted by mcjmdp:
We recently purchased MDP and we would like to write a script that will parse the file name of a report deposited on the MDP server and select the model, output disposition (email or file copy), and output location (user id). For example, zop0040_lmcclain_E.txt would imply we want to use model "zop0040" against this report text file and "E" implies we want to email it to user "lmcclain". Can this be done with scripting? Any and all thoughts and comments appreciated!
Thanks!