Hi, Readers.
We discussed Dynamics 365 Business Central: Conversion between Blob data type and Media/MediaSet data type the other day. Then I received an interesting question, is it possible to save the value of Work Description on Sales Order to Attachment Document? Yes, so in this post I will talk about it briefly.
Work Description field is a BLOB Data Type field, which usually contain multiline text. For example, on the Sales Order page:
table 36 “Sales Header”:
2. Dynamics 365 Business Central: How to export Work Description (Blob) in Sales Documents to excel
And on most list pages, cards, and documents, you can attach files on the Attachments tab of the FactBox pane. The number in the tab title indicates how many attached files exist for the card or document. For example, on the Sales Order page:
If you want to save the Work Description to Attachments, you need to add an additional step to save the Work Description as a text file (.txt) first, and then save this file in Attachments. At this point we can use a very simple method discussed earlier, Dynamics 365 Business Central: Using TextBuilder Data Type to export data to a text file
Let’s look at a simple example.
Test:
Great.
Test video:
Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
pageextension 50202 ZYSalesOrderExt extends "Sales Order"
{
actions
{
addbefore(Post)
{
action(CopyWorkDescriptionToAttachments)
{
ApplicationArea = All;
Caption = 'Copy Work Description to Attachments';
Image = Import;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
trigger OnAction()
var
InStr: InStream;
FileName: Text;
DocAttach: Record "Document Attachment";
WorkDescriptionLine: Text;
TxtBuilder: TextBuilder;
TempBlob: Codeunit "Temp Blob";
OutStr: OutStream;
begin
WorkDescriptionLine := '';
WorkDescriptionLine := Rec.GetWorkDescription();
if WorkDescriptionLine <> '' then begin
FileName := Format(CurrentDateTime, 0, '<Year><Month,2><Day,2> <Hours24,2>:<Minutes,2>');
TxtBuilder.AppendLine(WorkDescriptionLine);
TempBlob.CreateOutStream(OutStr);
OutStr.WriteText(TxtBuilder.ToText());
TempBlob.CreateInStream(InStr);
DocAttach.Init();
DocAttach.Validate("Table ID", Database::"Sales Header");
DocAttach.Validate("Document Type", Enum::"Sales Document Type"::Order);
DocAttach.Validate("No.", Rec."No.");
DocAttach.Validate("File Name", FileName);
DocAttach.Validate("File Extension", 'txt');
DocAttach."Document Reference ID".ImportStream(InStr, FileName);
DocAttach.Insert(true);
end
end;
}
}
}
}
Very simple, give it a try!!!😁
END
Hope this will help.
Thanks for reading.
ZHU
コメント