Announcement

As of April 17, 2018, this site is now in read-only mode. To start new Blackbaud Developer’s discussions, you will find Developer Discussions in the Blackbaud CRM Community.

To post or respond to Blackbaud Community discussions, you will have to login using a www.blackbaud.com login. Learn how to login here. If you have questions or need assistance, please email community@blackbaud.com.

Interacting with CRM exports from code

By: Joseph Styons

Posted on: June 1, 2015

BBCRM has the concept of Export Definitions and Exports. As their name implies, Exports allow you to drop data from CRM into an external file (often Excel or CSV).

The source of that data is typically an ad-hoc query.

Exports are useful. This post discusses how they can be leveraged programmatically.

You can find this project here:
https://bbcrmautoexporter.codeplex.com/

Note: if you are on 4.0 SP6 or higher, you will need to change the ‘target framework’ to 4.5 or higher in order to compile this project.
No other change should be necessary.

Since the Export process is a business process, the code shown here should also be helpful if you want to automate other CRM business processes.

Exports run as a business process.
They drop their output into a table which is created dynamically when the export finishes.
All business processes are accessible via a common handler, BusinessProcessInvoke.ashx.
That handler needs three arguments to kick off a business process:
DatabaseName
BusinessProcessID
and
ParameterSetID

If you want to call a business process programmatically, you need to do an http POST to that handler.
The export business process specifically has a guid of 64faa344-9c75-4c98-afe3-a40ec2df9249.

After you POST to that URL, the business process is running.
If you want to know when it finished, you will have to poll a separate endpoint to get feedback on the current status.
This is provided OOB by a View form. It’s the same view form you see when you are waiting for an export to complete.

The .NET class for that endpoint lives here:
Blackbaud.AppFx.Platform.Catalog.WebApiClient.ViewForms.BusinessProcessParameterSet.BusinessProcessParameterSetRecentStatusViewForm

Once that form tells you that the process has finished, you can count on an output table existing somewhere with the results.
This query will tell you the exact table name of the output (it will be a cryptic looking table with a guid as part of the name)
The @BUSINESSPROCESSPARAMETERSETID value will correspond to the value you POSTED as an argument when you kicked off the process.

SELECT TOP 1
BPC.ID
,BPC.NAME
,BPS.STATUS
,BPO.TABLENAME
,BPS.BUSINESSPROCESSPARAMETERSETID
FROM
BUSINESSPROCESSSTATUS BPS
INNER JOIN BUSINESSPROCESSCATALOG BPC ON BPC.ID = BPS.BUSINESSPROCESSCATALOGID
INNER JOIN BUSINESSPROCESSOUTPUT BPO ON BPO.BUSINESSPROCESSSTATUSID = BPS.ID
WHERE BPC.NAME = 'EXPORT PROCESS'
AND ((@BUSINESSPROCESSPARAMETERSETID is null) or (BPS.BUSINESSPROCESSPARAMETERSETID = @BUSINESSPROCESSPARAMETERSETID))
AND ((@MINIMUMDATE IS NULL) or (BPO.DATEADDED > @MINIMUMDATE))
AND BPS.STATUS = 'Completed'
ORDER BY
BPO.DATEADDED DESC

Once you have the table name, you can just SELECT it all, and drop it to a CSV or wherever you want.

All of the logic described here is contained in this project – specifically these two files:
\AutoExporter\CRMExport.vb
and
\AutoExporter.Catalog\Datalists\ExportOutputSets.Datalist.xml

The MetalWeb project encapsulates the datalist as a .NET class, so that you can call it from code easily.

I hope you find this post useful. At Wake Forest University, we found it helpful to drop the results of exports into a folder for a PROD and UPGRADE environment to verify that the upgraded exports matched what we had in our PROD one. If you find other uses, please leave a comment!

4 thoughts on “Interacting with CRM exports from code

  1. Great post. I was asking about this on the forum ages ago. Hope to make some good use out of it soon!

    Thanks

  2. nice J.R.
    Seems like there will be many uses for this going forward. I am just starting to look at our proposed interfaces which are really just exports.

  3. This absolutely useful, specially when you want to run business process/ exports in a queue and download results grammatically.

    Thank you JR

  4. This is absolutely useful, Specifically, on queued jobs / business processes and exports that one wants to download export results grammatically.

    Thank you JR.

Leave a Reply

Privacy Policy | Sitemap | © 2011 Blackbaud, Inc. All Rights Reserved

Digital Ocean