Introduction: In this article I will be giving the procedure to create custom folders according to the posting date of the posted sales invoices on the click of an action.
For example: If I select three posted sales invoices say A, B and C with posting dates as 1st Feb., 2018; 6th Feb., 2018 and 6th Jan., 2017 respectively. The code checks if folders viz. ‘2018_February’ and ‘2017_January’ are present in the mentioned location or not. If not, it will create the missing folders and the Posted Sales Invoice A and B will be saved in the ‘2018_February’ and Posted Sales Invoice C will be saved in ‘2017_January’ i.e. according to their posting dates. If the folder is already present, the Posted Sales Invoice will be saved in the respective folder.
Microsoft Dynamics NAV
In the similar way, create a custom action in Page 143 Posted Sales Invoices and add code to select multiple invoices with the help of SETSELECTIONFILTER.
For example: 2017_March
I have created a text variable FolderName which will have the custom folder name as mentioned above. The code for the same is given below:
Year := DATE2DMY(DocPostingDate,3); //This code gets the year from the posting date
MonthName := FORMAT(DocPostingDate,0,'<Month Text>');
FolderName := FORMAT(Year)+'_'+MonthName;
I have saved the Posting date of the posted sales invoice in the variable ‘DocPostingDate’.
Folder := // Save your folder path which can be entered in a custom setup table + ’\’ + FolderName;
IF NOT FileSystemAutomation.FolderExists(Folder) THEN
Procedure to save a record as a report-PDF document in the particular path in Dynamics NAV