The Spotfire Community is moving to TIBCOmmunity and this forum location has closed. During the transition, you can still search the old forums but posting has been disabled. We encourage you to pick up the discussion at the new Spotfire community on TIBCOmmunity.
Sending data to client via e-mail - TIBCO Spotfire Community

Sending data to client via e-mail

Last post Thu, Jun 28 2012 6:13 AM by Luvigz. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • Mon, Feb 20 2012 5:28 PM

    • Luvigz
    • Top 75 Contributor
    • Joined on Wed, Nov 9 2011
    • Posts 27

    Sending data to client via e-mail

    Ok. I've gotten this project to work with the below code by making a Datatable called UniqueNumbers be a DataOnDemand based on filters and marked rows a visualization. I'd like to, instead, simply use the crosstable visualization and only show those records which are marked and filtered. The only method I've been able to find an example of this for is the one which uses ExportText but that doesn't help me since I need to use a memory stream to create the file which I'm e-mailing to bypass security issues. Is there a way to directly access the rows of a cross table visualization to get the filtered/marked values from them without saving to a file first?

    import clr
    clr.AddReference("System.Data")
    clr.AddReference("System.Net")
    clr.AddReference("System")
    from Spotfire.Dxp.Data import DataValueCursor
    from Spotfire.Dxp.Data import DataPropertyClass
    from System import *
    from System.Net import *
    from System.Text import *
    from System import DateTime


    filename = "AvalaUniqueNo" + DateTime.Now.ToString() + ".csv"
    s="Unique Numbers\r\n"
    table=UniqueNumbers
    UniqueNumber=table.Columns["UniqueNo"]
    UniqueNumberVal=DataValueCursor.Create[str](UniqueNumber)

    for row in table.GetRows(UniqueNumberVal):
    s = s + UniqueNumberVal.CurrentValue + "\r\n"

    data = Encoding.ASCII.GetBytes(s)
    ms = IO.MemoryStream(data)

    MyMailMessage = Mail.MailMessage()

    #From requires an instance of the MailAddress type
    #Add in your own e-mail address if you want to test
    MyMailMessage.From = Mail.MailAddress("blah@blah.com")

    #To is a collection of MailAddress types
    #SSIEmailAddress is based on a drop down list. You can put whatever e-mail address you want to test this if you want to.
    MyMailMessage.To.Add(SSIEmailAddress)
    MyMailMessage.Subject = "Avala File"
    MyMailMessage.Body = "These are Unique Numbers sent by Avala and need to be processed for name and address information."
    ct = Mime.ContentType(Mime.MediaTypeNames.Text.Plain);
    attach = Mail.Attachment(ms, ct)
    attach.ContentDisposition.FileName = filename
    MyMailMessage.Attachments.Add(attach)
    ##Create the SMTPClient object and specify the SMTP GMail server
    SMTPServer = Mail.SmtpClient("smtp.gmail.com")
    SMTPServer.Port = 587
    #sorry can't give the Credentials below if you want to test you'll need your own
    SMTPServer.Credentials = Net.NetworkCredential("blahblah", "blahblah")
    SMTPServer.EnableSsl = True
    SMTPServer.Send(MyMailMessage)
    Mail.Attachment(ms, ct)
  • Tue, Feb 21 2012 11:08 AM In reply to

    • Luvigz
    • Top 75 Contributor
    • Joined on Wed, Nov 9 2011
    • Posts 27

    Re: Sending data to client via e-mail

    Ok.  I have gotten this to work with the ExportText with some help from support.  Modify the above up to the MyMailMessage = Mail.MailMessage() with:

    import clr
    clr.AddReference("System.Data")
    clr.AddReference("System.Net")
    clr.AddReference("System")
    from System import *
    from System.Net import *
    from System.Text import *
    from System import DateTime
    from Spotfire.Dxp.Application.Visuals import CrossTablePlot


    filename = "AvalaUniqueNo" + DateTime.Now.ToString() + ".csv"

    ms = IO.MemoryStream();

    sWriter = IO.StreamWriter(ms)

    #UniqueNumbers is the name of of a Cross Table Visualization added as a Script Parameter
    UniqueNumbers.As[CrossTablePlot]().ExportText(sWriter)

    ms.Seek(0, IO.SeekOrigin.Begin)
    memory = IO.StreamReader(ms)

    Everything below will stay the same.

  • Wed, Jun 27 2012 3:22 PM In reply to

    Re: Sending data to client via e-mail

    Hi

    Thanks for your post. Appreciated.

    I have a one query, Is this code will work only on cross table visualization or any other visualizations. If yes, please guide me .. where i need to change the code.. according to specific visualizations. let say : for scatter plot or bar/line chart.

    Thanks

  • Thu, Jun 28 2012 6:13 AM In reply to

    • Luvigz
    • Top 75 Contributor
    • Joined on Wed, Nov 9 2011
    • Posts 27

    Re: Sending data to client via e-mail

    I looked over the documentation on the ExportText method used to pull the data from the cross table and it is a member of the namespace for visuals so in theory it should work just the same as the cross table if you just replace the variable of the cross table with the one for the scatter plot or bar/line chart. Keep in mind the above is just pulling the data out of the cross table and sending out the data as a csv file so it isn't actually sending out the visual itself.   Also, the cross table format is pretty straight forward in regards to parsing the data and I have no idea if that will hold true for any of the other visuals except either the tables or cross tables.  One thing I might suggest is instead of trying to use the charts remove the navigation controls and make buttons for navigation and then create a non-navigatable page with a cross table for the data you want to export (this way also gives you the addtional option of adding in more data which might not be relevant in the visualization but is relevant for what you want included in the csv file). 
Page 1 of 1 (4 items)
┬ęCopyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center