To Export selected attachment for a record.
Aravindh_Navision
Member Posts: 258
Hi Friends,
[Version: NAV 2016]
I need to IMPORT/EXPORT/DELETE attachment and found a solution by browsing on internet. Below coding is working fine except for exporting multiple files for a record. I have given entire working code to show what I did.
New Table: Document Attachment Table with below fields.
1. Primary Key (RecordID)
2. Attachment (BLOB)
3. Extension (Text 30)
4. Document No. (Code 20)
5. Name of the File (Text 50)
6. Line No. (Integer)
Table: Global Variables
Filename (Text 1024)
ServerFilename (Text 1024)
FileManagement (Codeunit - File Management)
ExtensionStart (Integer)
TempBlob (Record - TempBlob)
Table: Text Constants
Table: Functions
ImportAttachment
ExportAttachment
DeleteAttachment
UpdateAttachment
RecordExist
ImportAttachment(RecIDToImport : RecordID)
ExportAttachment(RecIDToExport : RecordID;RecLineNo : Integer;RecNameofFile : Text)
DeleteAttachment(RecIDToDelete : RecordID)
UpdateAttachment(VAR RecIDToUpdate : RecordID)
RecordExist(RecIDToCheck : RecordID) : Boolean
I am calling the functions from Page (action pane) and those codings are given below.
Page - Global Variables
AttachmentManagement (Record - Document Attachment Table)
AttachmentRecRef (RecordRef)
AttachmentRecID (RecordID)
Page Functions
ImportAttachment - OnAction()
AttachmentManagement.MODIFY;
ExportAttachment - OnAction()
DeleteAttachment - OnAction()
When I tried to import files (multiple files), it is properly importing. But when I tried to export, only first attached file is exporting. Say when I try to export the third attachment for a record, the first attachment is only opening.
I believe it is a minor one but got struck up. Can anyone help how to solve this?
Thanks in advance.
[Version: NAV 2016]
I need to IMPORT/EXPORT/DELETE attachment and found a solution by browsing on internet. Below coding is working fine except for exporting multiple files for a record. I have given entire working code to show what I did.
New Table: Document Attachment Table with below fields.
1. Primary Key (RecordID)
2. Attachment (BLOB)
3. Extension (Text 30)
4. Document No. (Code 20)
5. Name of the File (Text 50)
6. Line No. (Integer)
Table: Global Variables
Filename (Text 1024)
ServerFilename (Text 1024)
FileManagement (Codeunit - File Management)
ExtensionStart (Integer)
TempBlob (Record - TempBlob)
Table: Text Constants
Text001 Do you want to overwrite existing attachment? Text002 Import attachment. Text003 Update attachment. Text004 No attachment in current document. Text005 Attachment File %1 imported successfully. Text006 Do you want to delete the attachment in %1?
Table: Functions
ImportAttachment
ExportAttachment
DeleteAttachment
UpdateAttachment
RecordExist
ImportAttachment(RecIDToImport : RecordID)
IF RecordExist(RecIDToImport) THEN EXIT; INIT; "Line No." := "Line No." + 10000; "Primary Key" := RecIDToImport; Filename := FileManagement.BLOBImportWithFilter(TempBlob,Text002,'','*.*|','*.*'); IF Filename = '' THEN EXIT; Attachment := TempBlob.Blob; "Name of the File" := FileManagement.GetFileName(Filename); Extension := '.' + FileManagement.GetExtension(Filename); INSERT; IF Attachment.HASVALUE THEN MESSAGE(Text005,Filename);
ExportAttachment(RecIDToExport : RecordID;RecLineNo : Integer;RecNameofFile : Text)
SETRANGE("Primary Key",RecIDToExport);
SETRANGE("Line No.",RecLineNo);
SETRANGE("Name of the File",RecNameofFile);
IF NOT FINDFIRST THEN
ERROR(Text004);
CALCFIELDS(Attachment);
IF NOT Attachment.HASVALUE THEN
ERROR(Text004);
TempBlob.Blob := Attachment;
FileManagement.BLOBExport(TempBlob,FORMAT('*' + Extension + ''),TRUE);
DeleteAttachment(RecIDToDelete : RecordID)
SETRANGE("Primary Key",RecIDToDelete);
IF NOT FINDFIRST THEN
ERROR(Text004);
CALCFIELDS(Attachment);
IF Attachment.HASVALUE THEN
IF CONFIRM(Text006,FALSE,RecIDToDelete) THEN
DELETE;
UpdateAttachment(VAR RecIDToUpdate : RecordID)
CALCFIELDS(Attachment); IF NOT CONFIRM(Text001) THEN EXIT; Filename := FileManagement.BLOBImportWithFilter(TempBlob,Text002,'','*.*|','*.*'); IF Filename = '' THEN EXIT; Attachment := TempBlob.Blob; "Name of the File" := FileManagement.GetFileName(Filename); Extension := '.' + FileManagement.GetExtension(Filename); MODIFY; IF Attachment.HASVALUE THEN MESSAGE(Text005,Filename);
RecordExist(RecIDToCheck : RecordID) : Boolean
SETRANGE("Primary Key",RecIDToCheck);
IF NOT FINDFIRST THEN
EXIT(FALSE);
UpdateAttachment(RecIDToCheck);
EXIT(TRUE);
I am calling the functions from Page (action pane) and those codings are given below.
Page - Global Variables
AttachmentManagement (Record - Document Attachment Table)
AttachmentRecRef (RecordRef)
AttachmentRecID (RecordID)
Page Functions
ImportAttachment - OnAction()
AttachmentRecRef.OPEN(DATABASE::"Purch. Request Header"); AttachmentRecRef.SETPOSITION(GETPOSITION); AttachmentRecID := AttachmentRecRef.RECORDID; AttachmentRecRef.CLOSE; AttachmentManagement.ImportAttachment(AttachmentRecID);AttachmentManagement."Document No." := "No.";
AttachmentManagement.MODIFY;
ExportAttachment - OnAction()
AttachmentRecRef.OPEN(DATABASE::"Purch. Request Header"); AttachmentRecRef.SETPOSITION(GETPOSITION); AttachmentRecID := AttachmentRecRef.RECORDID; AttachmentRecRef.CLOSE; AttachmentManagement.ExportAttachment(AttachmentRecID);
DeleteAttachment - OnAction()
AttachmentRecRef.OPEN(DATABASE::"Purch. Request Header"); AttachmentRecRef.SETPOSITION(GETPOSITION); AttachmentRecID := AttachmentRecRef.RECORDID; AttachmentRecRef.CLOSE; AttachmentManagement.DeleteAttachment(AttachmentRecID);
When I tried to import files (multiple files), it is properly importing. But when I tried to export, only first attached file is exporting. Say when I try to export the third attachment for a record, the first attachment is only opening.
I believe it is a minor one but got struck up. Can anyone help how to solve this?
Thanks in advance.
0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions