Add the SharePoint Connector FactBox to any page in Business Central

The SharePoint connector comes with the SharePoint fact box installed on many pages, but maybe you want the fact box somewhere else.

It’s not a problem. You can create an extension that takes a dependency on the SharePoint Connector and add the fact box to all the pages you need. (Or your partner can if you give them a link to this page).

First, add the dependency to your app.json like this:

{
  "id": "23ebd065-b289-4a68-85e3-b8410e360157",
  "name": "SharePoint Connector",
  "publisher": "hougaard.com",
  "version": "5.0.0.0"
}

Then, add one or more page extension objects to cover the places you need the fact box. Use the below snippet as a template. The only thing you need to do is edit the first line with:

  • Give it an object number
  • Give it a name
  • Replace the “PageNameToBeExtended” with the name of the page

You also add the part and the triggers to a page object to add the SharePoint Connector to custom pages.

 

pageextension <Object Number> "<Give it a Name>" extends <PageNameToBeExtended>
{
    layout
    {
        addfirst(factboxes)
        {
            part(SharePointPart_EFQ; "SharePoint Factbox EFQ")
            {
                ApplicationArea = All;
                Visible = SharePointActivated;
            }
        }
    }
    trigger OnAfterGetCurrRecord()
    var
        Mapping: Record "Table Mapping EFQ";
        SP: Codeunit "SharePoint EFQ";
        Ref: RecordRef;
        Parms: Dictionary of [Text, Text];
        EmptyData: Dictionary of [Text, Text];
    begin
        if SharePointActivated then
            if GuiAllowed then begin
                Ref.GetTable(Rec);
                SP.GetTableMapping(Mapping, Ref);
                CLEAR(Parms);
                Parms.Add('sitename', Mapping."Site Name");
                Parms.Add('basefolder', Mapping."Base Folder");
                Parms.Add('folder', CurrPage.SharePointPart_EFQ.Page.PrepareFill(Ref));
                if not CurrPage.EnqueueBackgroundTask(PageTaskId, Codeunit::"Factbox Background Task EFQ", Parms, 30000, PageBackgroundTaskErrorLevel::Warning) then begin
                    EmptyData.Add('data', '{"error":{"code":"-2147024894, System.IO.FileNotFoundException","message":{"lang":"en-US","value":"File Not Found."}}}');
                    CurrPage.SharePointPart_EFQ.Page.FinishFill(EmptyData);
                end;
            end;
    end;

    trigger OnPageBackgroundTaskCompleted(TaskId: Integer; Results: Dictionary of [Text, Text])
    begin
        if SharePointActivated then
            if TaskId = PageTaskId then
                CurrPage.SharePointPart_EFQ.Page.FinishFill(Results);
    end;

    trigger OnPageBackgroundTaskError(TaskId: Integer; ErrorCode: Text; ErrorText: Text; ErrorCallStack: Text; var IsHandled: Boolean)
    begin
        if SharePointActivated then
            if TaskId = PageTaskId then
                CurrPage.SharePointPart_EFQ.Page.FillError(ErrorText);
    end;

    trigger OnOpenPage()
    var
        TableMapping: Record "Table Mapping EFQ";
        Ref: RecordRef;
    begin
        Ref.GetTable(Rec);
        SharePointActivated := TableMapping.NeedsFactBox(Ref.Number());
    end;

    var
        SharePointActivated: Boolean;
        PageTaskId: Integer;
}