SharePoint Connector Documentation
Index

Conversion Routines

This page provides guidance on implementing custom conversion and transfer routines for the SharePoint Connector.

Overview

Conversion routines are custom procedures that:

  • Transfer attachments from BC to SharePoint
  • Convert document formats
  • Migrate data from other systems
  • Handle special document types

When to Use Custom Conversion

Scenarios

Scenario Standard Tool Custom Needed
BC attachments Transfer Attachments report Usually no
Incoming documents Incoming Documents feature Sometimes
External system migration No Yes
Special file handling No Yes

Custom Conversion Use Cases

  • Migrate from legacy document management
  • Convert file formats during transfer
  • Apply complex routing logic
  • Handle non-standard attachments

Open-Source Conversion App

Publisher Resources

The publisher may provide open-source examples:

  • Check publisher website
  • Review available samples
  • Use as starting point

Sample Conversion Pattern

codeunit 50100 "My Conversion Routine"
{
    procedure TransferDocuments(FilterCriteria: Text)
    var
        SourceRecord: Record "Source Table";
        SharePointEFQ: Codeunit "SharePoint EFQ";
    begin
        SourceRecord.SetFilter("No.", FilterCriteria);
        if SourceRecord.FindSet() then
            repeat
                TransferSingleDocument(SourceRecord);
            until SourceRecord.Next() = 0;
    end;

    local procedure TransferSingleDocument(SourceRecord: Record "Source Table")
    begin
        // Get document content
        // Determine destination
        // Upload to SharePoint
        // Update tracking
    end;
}

Attachment Conversion

Standard Attachments

BC stores attachments in Document Attachment table:

local procedure GetAttachments(RecordId: RecordId): Boolean
var
    DocumentAttachment: Record "Document Attachment";
begin
    DocumentAttachment.SetRange("Table ID", RecordId.TableNo);
    DocumentAttachment.SetRange("No.", GetRecordNo(RecordId));
    exit(DocumentAttachment.FindSet());
end;

Transferring Attachments

Basic pattern:

local procedure TransferAttachment(var DocAttachment: Record "Document Attachment"; DestinationPath: Text)
var
    TempBlob: Codeunit "Temp Blob";
    InStream: InStream;
begin
    // Export attachment to stream
    DocAttachment.CalcFields("Document Reference ID");
    TempBlob.FromRecord(DocAttachment, DocAttachment.FieldNo("Document Reference ID"));
    TempBlob.CreateInStream(InStream);

    // Upload to SharePoint
    // (Use SharePoint API codeunit)
end;

Incoming Document Conversion

Custom Matching

For complex matching requirements:

local procedure CustomMatch(FileName: Text; Content: Text): RecordId
var
    Customer: Record Customer;
    MatchFound: Boolean;
begin
    // Apply custom matching logic
    // Parse filename, content, or both
    // Return matched record
end;

Custom Processing

local procedure ProcessIncomingDocument(FilePath: Text)
begin
    // Download file
    // Apply OCR if needed
    // Match to record
    // Route to destination
    // Clean up source
end;

Long-Running Transfers

Token Refresh Strategy

For long transfers, maintain authentication:

local procedure TransferWithTokenRefresh(var Records: Record "Source Table")
var
    BatchSize: Integer;
    BatchCount: Integer;
begin
    BatchSize := 100;
    BatchCount := 0;

    if Records.FindSet() then
        repeat
            TransferSingleRecord(Records);
            BatchCount += 1;

            if BatchCount >= BatchSize then begin
                RefreshAccessToken();
                BatchCount := 0;
            end;
        until Records.Next() = 0;
end;

local procedure RefreshAccessToken()
var
    SharePointEFQ: Codeunit "SharePoint EFQ";
begin
    // Trigger token refresh
    SharePointEFQ.VerifyAccess();
end;

Error Recovery

Implement checkpoint recovery:

local procedure TransferWithRecovery(var Records: Record "Source Table"; StartFrom: Code[20])
begin
    if StartFrom <> '' then
        Records.SetFilter("No.", '>=%1', StartFrom);

    if Records.FindSet() then
        repeat
            if not TryTransfer(Records) then
                LogFailure(Records."No.");
        until Records.Next() = 0;
end;

Format Conversion

File Format Changes

If format conversion is needed:

local procedure ConvertAndUpload(SourceFile: Text; TargetFormat: Text)
begin
    // Read source file
    // Convert format (if applicable)
    // Upload converted file
end;

Supported Conversions

Common conversion needs:

  • Image format conversion
  • Document standardization
  • Compression/decompression

Reporting and Logging

Transfer Logging

Track transfer progress:

table 50100 "Transfer Log"
{
    fields
    {
        field(1; "Entry No."; Integer) { }
        field(2; "Source Table"; Integer) { }
        field(3; "Source No."; Code[20]) { }
        field(4; "Transfer Date"; DateTime) { }
        field(5; "Status"; Option) { OptionMembers = Pending,Success,Failed; }
        field(6; "Error Message"; Text[250]) { }
    }
}

Progress Reporting

For batch operations:

local procedure ReportProgress(Current: Integer; Total: Integer; RecordNo: Code[20])
begin
    // Update progress dialog
    // Log progress
    // Allow cancellation check
end;

Testing Conversion Routines

Test Strategy

Test Type Focus
Unit tests Individual procedures
Integration End-to-end flow
Volume Performance with many records
Error handling Failure scenarios

Test Data

Create test scenarios:

  • Various file types
  • Large files
  • Special characters
  • Missing data
  • Error conditions

Deployment Considerations

Production Deployment

Consideration Action
Backup Before any migration
Pilot Test with subset
Monitoring Watch for issues
Rollback Plan for problems

Performance

Factor Optimization
Batch size Balance throughput/memory
Timing Run during off-peak
Parallelization If supported