Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

Extracting Reports from the SalesLogix Plugin Table from External Applications

There are many reasons why extracting a SalesLogix Report from the SalesLogix database might be useful. There are possibilities of integration, automated running of reports, as well as the need to generate a PDF from some code on a server using a SalesLogix Crystal report.

SalesLogix stores reports in the DATA field, which is a binary (BLOB) field in the PLUGIN table. Not just the report, but the SalesLogix report plugin, which contains not only the report itself but also the plugin info for the report. All together in a single BLOB field. This BLOB field is the serialized Delphi class named TCRWReportWrapper with the report file bytes appended to the end of the serialized class bytes.

Luckily, a serialized Delphi class will always end in two consecutive NULL bytes (0x00, 0x00) and will never contain two consecutive NULL bytes internally. This makes out job a bit easier in knowing where the serialized Delphi class ends and the bytes making up the report file begin. We can read out the bytes from PLUGIN.DATA for the report record and then read through them until we find the two consecutive NULL bytes, when write out everything following to a file and we'll have the report itself.

Here is some C# code to do just that:

using System;
using System.Data;
using System.Data.OleDb;
using System.IO;

namespace FX.SalesLogix.Utility
{
public class ReportExtractor
{
public ReportExtractor(string ConnectionString)
{
this.ConnectionString = ConnectionString;
}

public string ConnectionString { get; set; }

public void GetReport(string PluginID, string DestinationFile)
{
using (OleDbConnection conn = new OleDbConnection(this.ConnectionString))
{
conn.Open();
using (OleDbCommand cmd = new OleDbCommand("SELECT DATA FROM PLUGIN WHERE PLUGINID = ?", conn))
{
cmd.Parameters.Add(new OleDbParameter("PLUGINID", PluginID));

// Get the plugin byte array
byte[] data = (byte[])cmd.ExecuteScalar();

// Look for the two consecutive null bytes
int idx = 0;
for (int i = 0; i < data.Length; i++)
{
if ((int)data[ i ] == 0 && (int)data[i + 1] == 0)
{
idx = i + 2;
break;
}
}

// Get everything after the two consecutive bytes
byte[] rpt = new byte[data.Length];
Array.Copy(data, idx, rpt, 0, data.Length - idx);

// Write out to an RPT file
using (FileStream f = new FileStream(DestinationFile, FileMode.CreateNew))
{
f.Write(rpt, 0, rpt.Length);
f.Close();
}
}
}
}
}
}

To use the code you'd do something like the following:

// Extract report to C:\MyReportFile.rpt
ReportExtractor rptextractor = new ReportExtractor(MyConnectionString);
rptextractor.GetReport("pDEMOA0000HQ", @"C:\MyReportFile.rpt");

Now you can do whatever you'd like with the report such as open it in an RDC object and generate a PDF from it.

What's This?
  
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series



Related Content
   Video: Demystifying Infor CRM (Saleslogix) Updates
Watch it now! If you missed yesterdays demo, "Demystifying Infor CRM (Saleslogix) Updates" ,
Posted on Sep 26, 2014 by Brianna Ojard to The Inbox
 
   Thoughts on the Future and Involvement in the Saleslogix/Infor CRM Community
Over the last year and a half I've been working on another product named Contatta. It's a great p
Posted on Sep 25, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Fixing the Orphaning of Salesfusion Data when Converting Leads to Contacts in Infor CRM (Saleslogix)
We have had a couple of client recently come to other with the same problem-When you convert a Lead to a
Posted on Sep 19, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Official Infor CRM Acquisition FAQ
What to expect now that Saleslogix is Infor CRM. Like many of you, it will take some time (probably a
Posted on Sep 18, 2014 by Brianna Ojard to The Inbox
 
   ComboFix Kills Saleslogix Sync
ComboFix, a third party malware utility, will alter the Operating system so .qts and .que files will no l
Posted on Sep 12, 2014 by Brianna Ojard to SalesLogix Support
 
Comments

 

Twitted by 4SalesLogix said:

Pingback from  Twitted by 4SalesLogix

May 30, 2009 2:49 PM
 

karim said:

nice & very helpful article

June 26, 2009 5:11 AM
 

Sonal said:

I am trying to set up access to the SSRS reports through saleslogix. When ever I click on the links on the custom aspx page the following error pops up.  I am new at this. So I would appreciate your guidance in the matter.

"

The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near '

"

December 18, 2012 9:51 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register