Community
Showing results for 
Search instead for 
Do you mean 
Reply

Filtering Company History by HistoryType

New Member
Posts: 5
Country: Canada

Filtering Company History by HistoryType

Hi folks,

 

I'm trying to get the set of "Library" documents for a given company, using GetHistories, and I'm running into serious problems with my filter criteria.  First I have a class that creates an instance of IFilterCriteria, accepting a SystemHistoryType in it's constructor (The idea being that I want to get the set of History objects of type "Library" only):

 

public class HistoryTypeFilter : IFilterCriteria
{
    string SQLClause = "";

    public HistoryTypeFilter(SystemHistoryType MySystemHistoryType)
    {
        HistoryFieldDescriptor HistoryTypeFD = new HistoryFieldDescriptor(HistoryField.HistoryTypeID);
        HistoryType MyHistoryType = new HistoryType(MySystemHistoryType);

        SQLClause = "[" + HistoryTypeFD.TableName + "].[" + HistoryTypeFD.ColumnName + "] = " + MyHistoryType.HistoryTypeId.ToString();
    }

    public String GetClause()
    {
        return SQLClause;
    }
}

 

Then I try to call GetHistories for a particular company:

 

                // no sort Critaria
                HistorySortCriteria[] CompanyHistorySortCriteria = { };

                // set of filter criteria
                IFilterCriteria[] CompanyHistoryFilterCriteria = { new HistoryTypeFilter(SystemHistoryType.Library) };

                HistoryList CompanyHistory = Framework.Histories.GetHistories( CompanyHistorySortCriteria,
                    MyCompany,
                    AggregationType.All,
                    CompanyHistoryFilterCriteria,
                    false);

 

This call fails with the exception:

 

[SqlException (0x80131904): The multi-part identifier "TBL_HISTORY.HISTORYTYPEID" could not be bound.]

 

I've tried using just the ColumnName - and that also tosses an error, saying that the reference to HISTORYTYPEID is ambigious, so any guidance on how to get that SQL clause sorted out would be much appreciated.

 

Scott

Employee
Posts: 1,163
Country: USA

Re: Filtering Company History by HistoryType

Hello Scott,

 

I happen to have a sample of accomplishing this same thing, however my approach is substantially different and I'm using contacts rather than companies, but that trivial.

 

//Grab a contact
Contact c = ActApp.ApplicationState.CurrentContact;
//Get a list of all of their documents
HistoryList myHList = ActApp.ActFramework.Histories.GetDocuments(c.ID);

 

This will return all the items on the document tab, aka histories of type Library Document.

 

Also, if you get the collection of history types from act, the frist item in the collection is Library Document:

 

HistoryType[] types = ActApp.ActFramework.Histories.GetHistoryTypes();

 

You can still use IFilterCriteria to filter the list, but this provides another alternative.

 

Hope this helps.

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 5
Country: Canada

Re: Filtering Company History by HistoryType

Hi Matthew,

 

Thanks for the alternative, however, I cannot filter the HistoryList that GetDocuments(guid) returns.  I need get the list of a specific file type (say for example, the set of Word documents) found in the Documents tab.  I believe using GetHistories() is my only recourse then.

 

My code also shows that you can use HistoryType LibraryHistoryType = new HistoryType(SystemHistoryType.Library) to get the right HistoryType.

 

Thanks,

 

Scott