Hi again,
I decided to expand on the example to include a lot of different field types. So, at this point I'm able to display several of the extrafields in the selection result:

There are some hickups;
- Bools never get checked
- reader.GetBoolean crashes when databasefield contains NULL
- Not sure how I can display the company name in the Company Relation?
- DateTime only displays datepart, not time.
- Date uses wrong format
- User relations doesn't show anything
- Searching on any of the fields will always give me the same, wrong, result.
Here is the full code of the archive provider so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SuperOffice.CRM.ArchiveLists;
using SuperOffice.CRM.Data;
using SuperOffice.Data;
using SuperOffice.Data.SQL;
namespace GEASExperiments
{
/*
* An ArchiveExtender for exposing ExtraFields from Service in Sales.
* This example assumes there are extrafields of various types on the crm7.contact table.
* https://community.superoffice.com/en/developer/forum/rooms/topic/netserver-api-group/core-components/extending-an-archive-to-include-extrafield/
* Frode Lillerud, 6.des 2017
*/
[ArchiveExtenderExtender("ContactWithExtraFieldsExtension", typeof(ContactExtenderBase), int.MaxValue / 2)]
public class ContactWithExtraFieldsExtender : TableExtenderBase<ContactTableInfo>
{
//Definition of the columns. NOTE - the variablename MUST start with _col to be detected by SuperOffice
private ArchiveColumnInfo _colNumberColumn
= new ArchiveColumnInfo("x_number", "Service Number", "Number field in Service",
Constants.DisplayTypes.Int, true, true, ColumnHelper.DefaultNumberWidth, Constants.RestrictionTypes.Int);
private FieldInfo xNumberField = null;
private ArchiveColumnInfo _colDateColumn
= new ArchiveColumnInfo("x_date", "Service Date", "Date field in Service",
Constants.DisplayTypes.Date, true, true, ColumnHelper.DefaultDateWidth, Constants.RestrictionTypes.Date);
private FieldInfo xDateField = null;
private ArchiveColumnInfo _colBoolColumn
= new ArchiveColumnInfo("x_bool", "Service Bool", "Bool field in Service",
Constants.DisplayTypes.Bool, true, true, ColumnHelper.DefaultCheckboxWidth, Constants.RestrictionTypes.Bool);
private FieldInfo xBoolField = null;
private ArchiveColumnInfo _colTextShortColumn
= new ArchiveColumnInfo("x_text_short", "Service Text Short", "Text (short) field in Service",
Constants.DisplayTypes.String, true, true, ColumnHelper.DefaultStringWidth, Constants.RestrictionTypes.String);
private FieldInfo xTextShortField = null;
private ArchiveColumnInfo _colTextLongColumn
= new ArchiveColumnInfo("x_text_long", "Service Text Long", "Text (long) field in Service",
Constants.DisplayTypes.String, true, true, ColumnHelper.DefaultStringWidth, Constants.RestrictionTypes.String);
private FieldInfo xTextLongField = null;
private ArchiveColumnInfo _colCompanyRelationColumn
= new ArchiveColumnInfo("x_company_relation", "Service Company Relation", "Company Relation field in Service",
Constants.DisplayTypes.Int, true, true, "15c", Constants.RestrictionTypes.Entity);
private FieldInfo xCompanyRelationField = null;
private ArchiveColumnInfo _colFloatColumn
= new ArchiveColumnInfo("x_float", "Service Float", "Float field in Service",
Constants.DisplayTypes.Decimal, true, true, "15c", Constants.RestrictionTypes.Decimal);
private FieldInfo xFloatField = null;
private ArchiveColumnInfo _colDateTimeColumn
= new ArchiveColumnInfo("x_datetime", "Service DateTime", "DateTime field in Service",
Constants.DisplayTypes.Datetime, true, true, "15c", Constants.RestrictionTypes.Datetime);
private FieldInfo xDateTimeField = null;
private ArchiveColumnInfo _colTimeColumn
= new ArchiveColumnInfo("x_time", "Service Time", "Time field in Service",
Constants.DisplayTypes.Time, true, true, "15c", Constants.RestrictionTypes.Datetime);
private FieldInfo xTimeField = null;
private ArchiveColumnInfo _colUserRelationColumn
= new ArchiveColumnInfo("x_user_relation", "Service User", "User Relation field in Service",
Constants.DisplayTypes.Icon, true, true, "15c", Constants.RestrictionTypes.Associate);
private FieldInfo xUserRelationField = null;
public ContactWithExtraFieldsExtender()
{
//Add our field under the "Company" heading, and not the "Others" heading.
SetIconHint(Constants.IconHints.Contact);
}
protected override void InnerModifyQuery()
{
//If we haven't gotten the field definitions yet, then get them.
if (xNumberField == null)
{
ContactTableInfo cti = Parent.TableToExtend as ContactTableInfo;
xNumberField = cti.FindField("x_number");
xDateField = cti.FindField("x_date");
xBoolField = cti.FindField("x_bool");
xTextShortField = cti.FindField("x_text_short");
xTextLongField = cti.FindField("x_text_long");
xCompanyRelationField = cti.FindField("x_company_relation");
xFloatField = cti.FindField("x_float");
xDateTimeField = cti.FindField("x_datetime");
xTimeField = cti.FindField("x_time");
xUserRelationField = cti.FindField("x_user_relation");
}
//Add the fields to the returned result.
if (xNumberField != null)
RootQuery.Query.ReturnFields.Add(xNumberField);
if (xDateField != null)
RootQuery.Query.ReturnFields.Add(xDateField);
if (xBoolField != null)
RootQuery.Query.ReturnFields.Add(xBoolField);
if (xTextShortField != null)
RootQuery.Query.ReturnFields.Add(xTextShortField);
if (xTextLongField != null)
RootQuery.Query.ReturnFields.Add(xTextLongField);
if (xCompanyRelationField != null)
RootQuery.Query.ReturnFields.Add(xCompanyRelationField);
if (xFloatField != null)
RootQuery.Query.ReturnFields.Add(xFloatField);
if (xDateTimeField != null)
RootQuery.Query.ReturnFields.Add(xDateTimeField);
if (xTimeField != null)
RootQuery.Query.ReturnFields.Add(xTimeField);
if (xUserRelationField != null)
RootQuery.Query.ReturnFields.Add(xUserRelationField);
}
protected override ContactTableInfo SetJoin()
{
return Parent.TableToExtend as ContactTableInfo;
}
protected override void InnerPopulateRowFromReader(SoDataReader reader, ArchiveRow row)
{
base.InnerPopulateRowFromReader(reader, row);
//Fill the column in the returned row with the value from the field.
if (xNumberField != null)
row.AddOverlappingIntColumn("x_number", reader.GetInt32(xNumberField));
if (xDateField != null)
row.AddOverlappingDateTimeColumn("x_date", reader.GetDateTime(xDateField));
if (xBoolField != null)
{
//bool b = false;
//try
//{
// b = reader.GetBoolean(xBoolField);
//}
//catch (Exception)
//{
// //Data in field is NULL.
//}
row.AddOverlappingBoolColumn("x_bool", true); //Problem - reader.GetBoolean crashes when DB contains NULL
}
if (xTextShortField != null)
row.AddOverlappingColumn("x_text_short", reader.GetString(xTextShortField));
if (xTextLongField != null)
row.AddOverlappingColumn("x_text_long", reader.GetString(xTextLongField));
if (xCompanyRelationField != null)
row.AddOverlappingIntColumn("x_company_relation", reader.GetInt32(xCompanyRelationField));
if (xFloatField != null)
row.AddOverlappingColumn("x_float", reader.GetDouble(xFloatField).ToString());
if (xDateTimeField != null)
row.AddOverlappingDateTimeColumn("x_datetime", reader.GetDateTime(xDateTimeField));
if (xTimeField != null)
row.AddOverlappingDateTimeColumn("x_time", reader.GetDateTime(xTimeField));
if (xUserRelationField != null)
row.AddOverlappingIntColumn("x_user_relation", reader.GetInt32(xUserRelationField));
}
}
}