Snippets Collections
InitInsert; New implementation
            if "No." = '' then begin
                TestNoSeries();
                NoSeriesCode := GetNoSeriesCode();
#if not CLEAN24
                NoSeriesMgt.RaiseObsoleteOnBeforeInitSeries(NoSeriesCode, xRec."No. Series", "Posting Date", "No.", "No. Series", IsHandled);
                if not IsHandled then begin
#endif
                    "No. Series" := NoSeriesCode;
                    if NoSeries.AreRelated("No. Series", xRec."No. Series") then
                        "No. Series" := xRec."No. Series";
                    "No." := NoSeries.GetNextNo("No. Series", "Posting Date");
                    SalesHeader2.ReadIsolation(IsolationLevel::ReadUncommitted);
                    SalesHeader2.SetLoadFields("No.");
                    while SalesHeader2.Get("Document Type", "No.") do
                        "No." := NoSeries.GetNextNo("No. Series", "Posting Date");
#if not CLEAN24
                    NoSeriesMgt.RaiseObsoleteOnAfterInitSeries("No. Series", NoSeriesCode, "Posting Date", "No.");
                end;
#endif
table 50075 "Sharepoint Documents"
{
    Caption = 'Sharepoint Documents';
    DataClassification = ToBeClassified;

    fields
    {
        field(1; "No."; Code[25])
        {
            DataClassification = ToBeClassified;

        }
        field(2; "Line No."; Integer)
        {
            DataClassification = ToBeClassified;
        }
        field(3; "SharePoint URL"; Text[2048])
        {
            DataClassification = ToBeClassified;
        }
        field(4; "File Name"; Text[250])
        {
            DataClassification = ToBeClassified;

        }
        field(5; "File Extension"; Text[50])
        {
            DataClassification = ToBeClassified;
        }
        field(6; "Table Id"; Integer)
        {
            DataClassification = ToBeClassified;
        }
        // field(7; "Document Type"; Option)
        // {
        //     OptionMembers = Quote,Order,Invoice,"Credit Memo","Blanket Order","Return Order";
        // }
        field(8; ID; Integer)
        {
            DataClassification = ToBeClassified;
            AutoIncrement = true;
        }
        field(9; "Document Code"; Code[20])
        {
            DataClassification = ToBeClassified;
        }
        field(10; "No. Series"; Code[20])
        {
            DataClassification = ToBeClassified;
        }
        field(11; "Document Type"; Option)
        {
            OptionMembers = Quote,Order,Invoice,"Credit Memo","Blanket Order","Return Order";
        }
        field(12; "Service Instruction Sheet"; boolean)
        {
            DataClassification = ToBeClassified;
        }
        field(13; "Exchange Rate Doc"; boolean)
        {
            DataClassification = ToBeClassified;
        }
        field(14; "Moved To Spoint"; Boolean)
        {
            DataClassification = ToBeClassified;
        }
        field(15; "Spoint Folder Relative Url"; Text[2048])
        {
            DataClassification = ToBeClassified;
        }

    }

    keys
    {
        key(Key1; "No.", "Line No.", "Table Id", ID, "Document Code")
        {
            Clustered = true;
        }
    }

    var
        CuNoSriemgmt: Codeunit NoSeriesManagement;

}


page 50159 "Sharepoint Documents1"
{
    PageType = List;
    ApplicationArea = All;
    UsageCategory = Lists;
    SourceTable = "Sharepoint Documents";


    layout
    {

        area(Content)
        {
            repeater(GroupName)
            {
                field("No."; "No.")
                {
                    ApplicationArea = All;

                }
                field("SharePoint URL"; "SharePoint URL")
                {
                    Editable = false;

                }
                field("File Name"; "File Name")
                {
                    trigger OnDrillDown()
                    var

                    begin
                        UploadDocumentForTheRecord("Table ID", "No.", "Document Code");
                    end;
                }
                field("File Extension"; "File Extension")
                {

                }
            }

        }
        area(Factboxes)
        {

        }
    }



    actions
    {
        area(processing)
        {
            action("View Document")
            {
                ApplicationArea = All;
                Image = Document;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction();
                begin
                    Hyperlink("SharePoint URL");
                end;
            }
            action("Download Document")
            {
                ApplicationArea = All;
                Image = Download;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction();
                var
                    ObjICTSetup: Record "ICT Setup";
                    CuDocMgt: Codeunit "SharePoint Integration Handler";
                    bas64String: Text;
                    BcInstream: InStream;
                    BcOutStream: OutStream;
                    DialogTitle: Label 'Download File';
                    Cubase64: Codeunit "Base64 Convert";
                    Cutemplob: Codeunit "Temp Blob";
                    tofileName: Text;
                    tofolder: Label 'C:\';
                    toFilter: Label 'All Files (*.*)|*.*';
                begin
                    ObjICTSetup.Get();
                    if ObjICTSetup."Use Sharepoint" then begin
                        bas64String := CuDocMgt.fnDownloadDocument("Spoint Folder Relative Url", "File Name");
                        bas64String := DelChr(bas64String, '<', '"');
                        bas64String := DelChr(bas64String, '>', '"');
                        tofileName := "File Name";
                        Cutemplob.CreateOutStream(BcOutStream);
                        Cubase64.FromBase64(bas64String, BcOutStream);
                        Cutemplob.CreateInStream(BcInstream);
                        DownloadFromStream(BcInstream, DialogTitle, tofolder, toFilter, tofileName);
                    end;
                end;
            }
            action("Delete Document")
            {
                ApplicationArea = All;
                Image = Delete;
                Promoted = true;
                PromotedCategory = Process;
                ToolTip = 'Delete Document From Sharepoint';
                trigger OnAction();
                var
                    ObjICTSetup: Record "ICT Setup";
                    CuDocMgt: Codeunit "SharePoint Integration Handler";
                    res: text;
                begin
                    ObjICTSetup.Get();
                    if ObjICTSetup."Use Sharepoint" then begin
                        res := CuDocMgt.fnDeleteDocument("Spoint Folder Relative Url", "File Name");
                    end;
                    if res = '200' then begin
                        if Delete(true) then begin
                            Message('Document Deleted Successfully');
                        end;
                    end;
                    Commit();
                    CurrPage.Update();
                end;
            }

        }
    }

    trigger OnNewRecord(BelowxRec: Boolean)
    var

    begin
        "File Name" := SelectFileTxt;
    end;

    trigger OnAfterGetRecord()
    begin

    end;

    procedure UploadDocumentForTheRecord(TableId: Integer; RecordNo: code[25]; DocCode: Code[25])
    var
        FieldRef: FieldRef;
        DocType: Option;
        LineNo: Integer;
        ColumnPropertArray: array[6] of Text[250];
        i: Integer;
        ObjPurchInvHeader: Record "Purch. Inv. Header";
        ObjPurchRcptHeader: Record "Purch. Rcpt. Header";
        ObjPurchCrMemoHdr: Record "Purch. Cr. Memo Hdr.";
        ObjSalesHeader: Record "Sales Header";
        ObjBankAccRecon: Record "Bank Acc. Reconciliation";
        ObjEft: Record "EFT Generator";
        FoldersArray: array[5] of Text[250];
    begin
        ObjcompInfo.get;
        ObjSpStp.Reset();
        ObjSpStp.SetRange(ObjSpStp."Table Id", TableId);
        if ObjSpStp.FindFirst() then begin
            case
                TableId of
                Database::"Purchase Header":
                    begin
                        ObjPurchHeader.get(RecordNo);
                        FoldersArray[1] := ObjSpStp.Folder;
                        FoldersArray[2] := ObjSpStp.Module;
                        FoldersArray[3] := ObjSpStp."Financial Year";
                        FoldersArray[4] := Format(ObjPurchHeader."Document Type");
                        FoldersArray[5] := RecordNo;
                        ParseTheDocumentToSharepointHandler(FoldersArray);
                    end;               
            end;
        end;
    end;

    procedure ParseTheDocumentToSharepointHandler(FolderArray: array[5] of Text[250])
    var
        ServerFileName: Text[250];
        ObjIctSetup: Record "ICT Setup";
        ClientPath: Text[250];
        clientFileName: Text[250];
        TempFileName: Text[250];
        cuTemplob: Codeunit "Temp Blob";
        DialogTitle: Label 'Select File';
        base64String: Text;
        cuBase64: Codeunit "Base64 Convert";
        fromFilter: label 'All Files (*.*)|*.*';
        BcInstream: InStream;
        bcOutStream: OutStream;
        BcFile: File;
        Exfilter: label '(*.*)|*.*';
        FromFolder: label 'C:\';
        filename: Text[250];
    begin
        Commit();

        ObjIctSetup.Get();
        File.UploadIntoStream(DialogTitle, FromFolder, FromFilter, clientFileName, BcInstream);
        base64String := cuBase64.ToBase64(BcInstream);
        filename := FileManagement.GetFileName(clientFileName);
        "SharePoint URL" := CuDocMgmt.fnuploadDocument(base64String, FolderArray, filename);
        "File Name" := filename;
        "File Extension" := FileManagement.GetExtension(filename);
        "Spoint Folder Relative Url" := '/' + FolderArray[1] + '/' + FolderArray[2] + '/' + FolderArray[3] + '/' + FolderArray[4] + '/' + FolderArray[5];
    end;

    procedure OpenForRecReference(RecRef: RecordRef)

    var
        FieldRef: FieldRef;
        RecNo: Code[20];
        RecNo2: Code[20];
        DocType: Option;
        LineNo: Integer;
        DoCNo: Code[25];

    begin
        Reset();
        FromRecRef := RecRef;
        SetRange("Table ID", RecRef.Number);       
        CASE RecRef.NUMBER OF
            DATABASE::"Sales Header",
            DATABASE::"Sales Line",
            DATABASE::"Purchase Header",
            DATABASE::"Purchase Line":
                BEGIN
                    FieldRef := RecRef.FIELD(1);
                    DocType := FieldRef.VALUE;
                    SETRANGE("Document Type", DocType);

                    FieldRef := RecRef.FIELD(3);
                    RecNo := FieldRef.VALUE;
                    SETRANGE("No.", RecNo);

                    FlowFieldsEditable := FALSE;
                END;
        END;
        
    end;

    var
        FromRecRef: RecordRef;
        UrlText: Text[250];
        GLAccount: Record "G/L Account";
        SalesDocumentFlow: Boolean;
        PurchaseDocumentFlow: Boolean;
        FlowFieldsEditable: Boolean;
        ObjIctStupRec: Record "ICT Setup";

        Attachment: Page "Document Attachment Details";
        SelectFileTxt: TextConst ENU = 'Select File...';
        TbUserSetup: Record "User Setup";
        ObjSpStp: Record "Sharepoint Setup";
        CuDocMgmt: Codeunit "SharePoint Integration Handler";
        ObjcompInfo: Record "Company Information";
        ObjPayments: Record Payments;
        ObjPaylines: Record "Payment Lines";
        ObjPurchHeader: Record "Purchase Header";
        ObjStaffAdvance: Record Payments;
        storereq: Record "Store Requistion Header";
        prepaymentsheader: Record "Prepayments Header";
        ObjProposedBudget: Record "Proposed Budget Header";
        objBudgReallocation: Record "Budget Reallocation";
        ObjBudget: Record "Budget Approval Header";
        FileManagement: Codeunit "File Management";
        FileName: Text;
        ImportTxt: label 'Attach a document.';
        FileDialogTxt: TextConst ENU = 'Attachments (%1)|%1';
        FilterTxt: TextConst ENU = '*.jpg;*.jpeg;*.bmp;*.png;*.gif;*.tiff;*.tif;*.pdf;*.docx;*.doc;*.xlsx;*.xls;*.pptx;*.ppt;*.msg;*.xml;*.*';
        FolderArray: array[5] of Text[250];
        i: Integer;
}

table 50076 "Sharepoint Setup"
{
    Caption = 'Sharepoint Setup';
    DataClassification = ToBeClassified;

    fields
    {
        field(1; No; Integer)
        {
            DataClassification = ToBeClassified;

        }

        field(2; "Shortcut Dimension 2 Code"; Code[20])
        {
            CaptionClass = '1,1,2';
            TableRelation = "Dimension Value".Code WHERE("Global Dimension No." = CONST(2));

            trigger OnValidate()
            begin
            end;
        }
        field(3; "Sharepoint Url"; text[250])
        {
            DataClassification = ToBeClassified;
        }

        // field(4; "Document Type"; Enum "Sharepoint Document types")
        // {
        //     DataClassification = ToBeClassified;
        // }
        field(5; "Library"; Text[150])
        {
            DataClassification = ToBeClassified;
        }
        field(6; "Folder"; Text[150])
        {
            DataClassification = ToBeClassified;
        }
        field(7; "Financial Year"; Text[50])
        {
            DataClassification = ToBeClassified;
        }
        field(8; "Quarter"; Text[50])
        {
            DataClassification = ToBeClassified;
        }
        //Module
        field(9; "Module"; Text[50])
        {
            DataClassification = ToBeClassified;
        }
        //Sub-Module By
        field(10; "Sub-Module By"; Option)
        {
            DataClassification = ToBeClassified;
            OptionMembers = "Payment Type/Document Type",None;
        }
        //Sub-Module
        field(11; "Sub-Module"; Text[50])
        {
            DataClassification = ToBeClassified;
        }
        //table Id
        field(12; "Table Id"; Integer)
        {
            DataClassification = ToBeClassified;
            TableRelation = AllObjWithCaption."Object ID" where("Object Type" = CONST(Table));
            trigger OnValidate()
            var
                ObjAllObjWithCaption: Record "AllObjWithCaption";
            begin
                ObjAllObjWithCaption.Reset();
                ObjAllObjWithCaption.SetRange("Object ID", "Table Id");
                ObjAllObjWithCaption.SetRange("Object Type", ObjAllObjWithCaption."Object Type"::Table);
                if ObjAllObjWithCaption.FindFirst() then
                    "Table Name" := ObjAllObjWithCaption."Object Name";

            end;
        }
        //table Name
        field(13; "Table Name"; Text[50])
        {
            DataClassification = ToBeClassified;
        }

    }

    keys
    {
        key(Key1; No)
        {
            Clustered = true;
        }
    }

    var
        myInt: Integer;

    trigger OnInsert()
    begin

    end;

    trigger OnModify()
    begin

    end;

    trigger OnDelete()
    begin

    end;

    trigger OnRename()
    begin

    end;

}
    procedure fnuploadDocument(docToUpload: Text; foldersArray: array[5] of Text; docName: Text): Text
    var
        httpClient: HttpClient;
        httpContent: HttpContent;
        httpResponseMessage: HttpResponseMessage;
        httpContentHeaders: HttpHeaders;
        HttpRequestMessage: HttpRequestMessage;
        apiUrl: Text;
        Responsetxt: Text;
        JSonRequest: JsonObject;
        FolderTxt: Text;
        RequestmesgTxt: Text;
        RequestBody: Text;
        RequestType: Enum "Http Requests Enum";
        JsonResp: JsonObject;
        fileUrl: Text;
        JsonToken: JsonToken;
        JsonArray: JsonArray;
        statustxt: Text;
    begin
        ObjIctSetup.GET;
        apiUrl := ObjIctSetup."Sharepoint Integrat. Base URL" + 'sharepoint/file';
        FolderTxt := '/' + foldersArray[1] + '/' + foldersArray[2] + '/' + foldersArray[3] + '/' + foldersArray[4] + '/' + foldersArray[5];
        RequestBody += '{';
        RequestBody += '"fileName":"' + docName + '",';
        RequestBody += '"fileContent":"' + doctoupload + '",';
        RequestBody += '"folderName":"' + folderTxt + '"';
        RequestBody += '}';
        Responsetxt := CallService(apiUrl, RequestType::post, RequestBody, '', '', ObjIctSetup."Sharepoint Api Key");
        JsonResp.ReadFrom(Responsetxt);
        JsonResp.Get('status', JsonToken);
        statustxt := JsonToken.AsValue().AsText();
        if statustxt = '200' then begin
            JsonResp.Get('data', JsonToken);
            JsonResp := JsonToken.AsObject();
            JsonResp.Get('fileUrl', JsonToken);
            fileUrl := JsonToken.AsValue().AsText();
            exit(fileUrl);
        end else begin
            Error('Error uploading document');
        end;
    end;

    procedure fnDownloadDocument(folderRelativeUrl: Text; docName: Text): Text
    var
        httpClient: HttpClient;
        httpContent: HttpContent;
        httpResponseMessage: HttpResponseMessage;
        httpContentHeaders: HttpHeaders;
        HttpRequestMessage: HttpRequestMessage;
        apiUrl: Text;
        Responsetxt: Text;
        JSonRequest: JsonObject;
        FolderTxt: Text;
        RequestmesgTxt: Text;
        CuRest: Codeunit "Web Service Management";
        RequestBody: Text;
        RequestType: Enum "Http Requests Enum";
        JsonResp: JsonObject;
        fileUrl: Text;
        JsonToken: JsonToken;
        JsonArray: JsonArray;
        doctoupload: Text;
        statustxt: Text;
    begin
        ObjIctSetup.GET;
        apiUrl := ObjIctSetup."Sharepoint Integrat. Base URL" + 'sharepoint/download';
        RequestBody += '{';
        RequestBody += '"fileName":"' + docName + '",';
        RequestBody += '"fileContent":"' + doctoupload + '",';
        RequestBody += '"folderName":"' + folderRelativeUrl + '"';
        RequestBody += '}';
        Responsetxt := CallService(apiUrl, RequestType::post, RequestBody, '', '', ObjIctSetup."Sharepoint Api Key");
        if Responsetxt <> '' then begin
            exit(Responsetxt);
        end else begin
            Error('Error downloading document');
        end;
    end;

    procedure fnDeleteDocument(folderRelativeUrl: Text; docName: Text): Text
    var
        httpClient: HttpClient;
        httpContent: HttpContent;
        httpResponseMessage: HttpResponseMessage;
        httpContentHeaders: HttpHeaders;
        HttpRequestMessage: HttpRequestMessage;
        apiUrl: Text;
        Responsetxt: Text;
        JSonRequest: JsonObject;
        FolderTxt: Text;
        RequestmesgTxt: Text;
        CuRest: Codeunit "Web Service Management";
        RequestBody: Text;
        RequestType: Enum "Http Requests Enum";
        JsonResp: JsonObject;
        fileUrl: Text;
        JsonToken: JsonToken;
        JsonArray: JsonArray;
        doctoupload: Text;
    begin
        ObjIctSetup.GET;
        apiUrl := ObjIctSetup."Sharepoint Integrat. Base URL" + 'sharepoint/file:delete';
        RequestBody += '{';
        RequestBody += '"fileName":"' + docName + '",';
        RequestBody += '"fileContent":"' + doctoupload + '",';
        RequestBody += '"folderName":"' + folderRelativeUrl + '"';
        RequestBody += '}';
        Responsetxt := CallService(apiUrl, RequestType::post, RequestBody, '', '', ObjIctSetup."Sharepoint Api Key");
        JsonResp.ReadFrom(Responsetxt);
        JsonResp.Get('status', JsonToken);
        exit(JsonToken.AsValue().AsText()); 
    end;
enum 50005 "Http Requests Enum"
{
    Extensible = true;
    value(0; Get) { }
    value(1; patch) { }
    value(2; post) { }
    value(3; delete) { }
}



procedure CallWebService(RequestUrl: Text; RequestType: Enum "Http Requests Enum"; payload: Text; Username: Text; Password: Text; ApiKey: text): Text
    var
        Client: HttpClient;
        RequestHeaders: HttpHeaders;
        RequestContent: HttpContent;
        ResponseMessage: HttpResponseMessage;
        RequestMessage: HttpRequestMessage;
        ResponseText: Text;
        contentHeaders: HttpHeaders;
        folderName: Text;
        FileName: Text;
        fielcontent: Text;
    begin
        RequestHeaders := Client.DefaultRequestHeaders();

        case RequestType of
            RequestType::Get:
                begin
                    RequestContent.WriteFrom(payload);

                    RequestContent.GetHeaders(contentHeaders);
                    contentHeaders.Clear();
                    contentHeaders.Add('Content-Type', 'application/json');
                    if ApiKey <> '' then
                        contentHeaders.Add('XApiKey', ApiKey);
                    RequestMessage.Content := RequestContent;
                    RequestMessage.SetRequestUri(RequestURL);
                    RequestMessage.Method := 'GET';

                    Client.send(RequestMessage, ResponseMessage);
                end;
            // Client.Get(RequestURL, ResponseMessage);
            RequestType::patch:
                begin
                    RequestContent.WriteFrom(payload);

                    RequestContent.GetHeaders(contentHeaders);
                    contentHeaders.Clear();
                    contentHeaders.Add('Content-Type', 'application/json-patch+json');
                    if ApiKey <> '' then
                        contentHeaders.Add('XApiKey', ApiKey);

                    RequestMessage.Content := RequestContent;

                    RequestMessage.SetRequestUri(RequestURL);
                    RequestMessage.Method := 'PATCH';

                    client.Send(RequestMessage, ResponseMessage);
                end;
            RequestType::post:
                begin
                    RequestContent.WriteFrom(payload);

                    RequestContent.GetHeaders(contentHeaders);
                    contentHeaders.Clear();
                    contentHeaders.Add('Content-Type', 'application/json');
                    if ApiKey <> '' then
                        contentHeaders.Add('XApiKey', ApiKey);

                    Client.Post(RequestURL, RequestContent, ResponseMessage);
                end;
            RequestType::delete:
                Client.Delete(RequestURL, ResponseMessage);
        end;
        ResponseMessage.Content().ReadAs(ResponseText);
        exit(ResponseText);
    end;


}
star

Tue May 14 2024 08:46:32 GMT+0000 (Coordinated Universal Time) https://kepty.cz/2024/02/18/replace-noseriesmanagement-with-the-new-bc-foundation-no-series-app-1-2/

#al
star

Mon Jan 01 2024 22:58:24 GMT+0000 (Coordinated Universal Time)

#al
star

Mon Jan 01 2024 22:46:36 GMT+0000 (Coordinated Universal Time)

#al
star

Mon Jan 01 2024 22:33:59 GMT+0000 (Coordinated Universal Time)

#al

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension