|
20.02.2018, 16:11 | #1 |
Участник
|
alexef: Sample Extension v2.0 — Dynamics NAV / AL extension / SaaS — ALF Export Setup Tabs to Excel
Источник: https://blogs.technet.microsoft.com/...tabs-to-excel/
============== In this blog post I will try to show an example of creating an extension v2.0 (AL extension). This is will be the extension for Dynamics 365 for Finance and Operations, Business edition system (Cloud NAV), in other words: the app for SaaS environment. A good start point for an extension story: Getting Started with AL For the questions and searches you could use GitHub page: https://github.com/Microsoft/AL/issues In my scenario I firstly create an object via classic way (Object Designer, on-prem version) and after that convert this object to AL object with use The Txt2Al Conversion Tool. GitHub project: https://github.com/finn777/ALF-Expor...-Tabs-to-Excel Before start I have in my hands --- - NAV 2018 (W1) CU 02, build 20348 system: - Cloud sandbox (microsoft-sandbox): Remember that you not one in this sandbox. // In general, you could see that Users page shows more than one line. BUT if you need you always can do Reset Sandbox and start from a clean environment. -Visual Studio Code with AL Language extension: // ‘Visual Studio Code’ is not ‘Visual Studio’ Well, what my extension going to do. I’ll try to create a ‘processing only’ report that export a few Setup tables to the Excel. An analog of how to do it via Configuration Packages: We are trying to create Excel file via one click and add some improvements: all data on the one sheet, add some additional info and etc.. For the Excel export purpose I am going to use the functions from Table Excel Buffer (370). I use report with no data item and with ProcessingOnly=Yes; UseRequestPage=No Why I use a report? Because you could add Pages and Reports to Search in Cloud system. // Adding Pages and Reports to Search During building an object that are going to be run under Cloud (SaaS) remember that not all functions / objects could be used in extension v2.0 (AL extension). You should use function that has Property FunctionVisibility = External // Question: FunctionVisibility Most virtual/system tables are currently not allowed for usage in AL extension. // Remember Modern DEV (AL) story is very fresh and change / improvement every month I like this sentence from the on-line help (Testing your Extension): Always test in a true Dynamics 365 for Finance and Operations, Business edition SaaS environment. If you test in on-prem, you might miss errors that would be seen on SaaS. My object ALF Export Setup Tabs to Excel (Original_on-prem).txt: === OBJECT Report 50126 ALF Export Setup Tabs to Excel { OBJECT-PROPERTIES { Date=20.02.18; Time=[ 9:50:13]; Modified=Yes; Version List=1.0; } PROPERTIES { ProcessingOnly=Yes; OnPreReport=BEGIN TempExcelBuffer.DELETEALL; RowNo := 1; ColNo := 1; EnterCell(RowNo,ColNo,FORMAT(COMPANYPROPERTY.URLNAME+';'+TENANTID+';'+USERID+';'+FORMAT(TIME)),TempExcelBuffer."Cell Type"::Text,TRUE,FALSE,TRUE); StartRowNo := 3; END; OnPostReport=BEGIN GlobalRecRef.OPEN(DATABASE::"General Ledger Setup"); GlobalRecRef.FINDFIRST; FillHeader(StartRowNo,GlobalRecRef); StartRowNo := FillLine(StartRowNo,GlobalRecRef) + 2; GlobalRecRef.CLOSE; GlobalRecRef.OPEN(DATABASE::"Sales & Receivables Setup"); GlobalRecRef.FINDFIRST; FillHeader(StartRowNo,GlobalRecRef); StartRowNo := FillLine(StartRowNo,GlobalRecRef) + 2; GlobalRecRef.CLOSE; GlobalRecRef.OPEN(DATABASE::"Purchases & Payables Setup"); GlobalRecRef.FINDFIRST; FillHeader(StartRowNo,GlobalRecRef); StartRowNo := FillLine(StartRowNo,GlobalRecRef) + 2; GlobalRecRef.CLOSE; GlobalRecRef.OPEN(DATABASE::"Inventory Setup"); GlobalRecRef.FINDFIRST; FillHeader(StartRowNo,GlobalRecRef); StartRowNo := FillLine(StartRowNo,GlobalRecRef) + 2; GlobalRecRef.CLOSE; TempExcelBuffer.CreateNewBook(SheetName); TempExcelBuffer.WriteSheet(SheetName,'',''); TempExcelBuffer.CloseBook; TempExcelBuffer.OpenExcel; TempExcelBuffer.GiveUserControl; // please comment this line for Cloud app END; UseRequestPage=No; } DATASET { } REQUESTPAGE { PROPERTIES { } CONTROLS { } } LABELS { } CODE { VAR TempExcelBuffer@1000 : TEMPORARY Record 370; RowNo@1001 : Integer; ColNo@1002 : Integer; GlobalRecRef@1003 : RecordRef; StartRowNo@1004 : Integer; SheetName@1005 : TextConst 'ENU="ENU=ALF Export Setup Tabs to Excel"'; LOCAL PROCEDURE EnterCell@1(RowNo@1000 : Integer;ColumnNo@1001 : Integer;CellValue@1002 : Text[250];CellType@1003 : 'Number,Text,Date,Time';Bold@1004 : Boolean;Italic@1005 : Boolean;Underline@1006 : Boolean); BEGIN TempExcelBuffer.INIT; TempExcelBuffer.VALIDATE("Row No.",RowNo); TempExcelBuffer.VALIDATE("Column No.",ColumnNo); TempExcelBuffer."Cell Value as Text" := CellValue; TempExcelBuffer."Cell Type" := CellType; TempExcelBuffer.Bold := Bold; TempExcelBuffer.Italic := Italic; TempExcelBuffer.Underline := Underline; TempExcelBuffer.INSERT; END; LOCAL PROCEDURE FillHeader@4(StartRowNo@1001 : Integer;LocalRecRef@1002 : RecordRef); VAR LocalFieldRef@1000 : FieldRef; BEGIN RowNo := StartRowNo; ColNo := 1; EnterCell(RowNo,ColNo,LocalRecRef.CAPTION + ' ('+FORMAT(LocalRecRef.NUMBER)+')',TempExcelBuffer."Cell Type"::Text,TRUE,TRUE,TRUE); ColNo := 2; EnterCell(RowNo,ColNo,'VALUE',TempExcelBuffer."Cell Type"::Text,TRUE,TRUE,TRUE); ColNo := 3; EnterCell(RowNo,ColNo,'CLASS',TempExcelBuffer."Cell Type"::Text,TRUE,TRUE,TRUE); ColNo := 4; EnterCell(RowNo,ColNo,'OPTION',TempExcelBuffer."Cell Type"::Text,TRUE,TRUE,TRUE); ColNo := 1; FOR RowNo := (1 + StartRowNo) TO (LocalRecRef.FIELDCOUNT + StartRowNo) DO BEGIN LocalFieldRef := LocalRecRef.FIELDINDEX(RowNo - StartRowNo); EnterCell(RowNo,ColNo,LocalFieldRef.CAPTION + ' ('+FORMAT(LocalFieldRef.NUMBER)+')',TempExcelBuffer."Cell Type"::Text,TRUE,FALSE,FALSE); END; END; LOCAL PROCEDURE FillLine@6(StartRowNo@1001 : Integer;LocalRecRef@1002 : RecordRef) : Integer; VAR LocalFieldRef@1000 : FieldRef; BEGIN FOR RowNo := (1 + StartRowNo) TO (LocalRecRef.FIELDCOUNT + StartRowNo) DO BEGIN LocalFieldRef := LocalRecRef.FIELDINDEX(RowNo - StartRowNo); ColNo := 2; EnterCell(RowNo,ColNo,FORMAT(LocalFieldRef.VALUE),TempExcelBuffer."Cell Type"::Text,FALSE,FALSE,FALSE); ColNo := 3; EnterCell(RowNo,ColNo,FORMAT(LocalFieldRef.CLASS),TempExcelBuffer."Cell Type"::Text,FALSE,FALSE,FALSE); ColNo := 4; EnterCell(RowNo,ColNo,FORMAT(LocalFieldRef.OPTIONCAPTION),TempExcelBuffer."Cell Type"::Text,FALSE,FALSE,FALSE); END; EXIT(RowNo); END; BEGIN { //Please add these properties for Cloud app //Caption = 'ALF Export Setup Tabs to Excel'; //UsageCategory = ReportsAndAnalysis; //ApplicationArea = All,Basic,Suite; } END. } RDLDATA { } } === You could run it in on-prem version: Now let’s use The Txt2Al Conversion Tool cd C:\Program Files (x86)\Microsoft Dynamics NAV\110\RoleTailored Client finsql.exe Command=ExportToNewSyntax, File="C:\Users\alexef\Documents\ALF Export Setup Tabs to Excel\Convert_Objects\Objects_on-prem_NewSyntax_NEW\ALF Export Setup Tabs to Excel.txt", Database="Demo Database NAV (11-0)", ServerName="RU-ALEXEF07\NAV2018", Filter=Type=report;ID=50126 txt2al.exe --source="C:\Users\alexef\Documents\ALF Export Setup Tabs to Excel\Convert_Objects\Objects_on-prem_NewSyntax_NEW" --target="C:\Users\alexef\Documents\ALF Export Setup Tabs to Excel\Convert_Objects\Objects_AL" --rename --type=Report --extensionStartId=70050126 Rename object according Best Practices for AL Run ‘Visual Studio Code’: AL:Go! Set new folder for AL project: C:\Users\alexef\Documents\ALF Export Setup Tabs to Excel\AL\ALF Export Setup Tabs to Excel Select from dropdown list: Microsoft cloud sandbox launch.json automatically set like this: app.json automatically set like this: AL:Download symbols Set “publisher” (!): AL:Publish // F5 Okay, now close Visual Studio Code, go to our project folder, delete HelloWorld.all file and add Rep50126.ALF Export Setup Tabs to Excel.al file: Open Visual Studio Code and comment function TempExcelBuffer.GiveUserControl: Remember this function has FunctionVisibility = Internal // not External: Set (uncomment) specific Cloud properties: AL:Publish // F5 Now try to run object directly: https://microsoft-sandbox.financials.../?report=50126 After re-login you could see that a user could search this object too: And finally, you could see our extension in the list: Источник: https://blogs.technet.microsoft.com/...tabs-to-excel/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
За это сообщение автора поблагодарили: Sancho (1). |
01.03.2018, 16:42 | #2 |
Участник
|
|
|
|
За это сообщение автора поблагодарили: Sancho (1). |
02.03.2018, 16:37 | #3 |
Участник
|
Additional info:
For you own Cloud sandbox you could use link: Dynamics 365 for Finance and Operations, Business edition Sandbox tenant https://aka.ms/getsandboxforfinancials You should set launch.json: { "version": "0.2.0", "configurations": [ { "type": "al", "request": "launch", "name": "cloud", "startupObjectId": 22 } ] } AL: Clear credentials cache AL: Download symbols Sign with e-mail that has been set during creation sandbox: Now you can run AL: Publish … and later run report in system: |
|
05.10.2018, 23:13 | #4 |
Участник
|
When you create Extensions V2 for internal usage, specify target property to "Internal". So you can use all global functions, not only external
|
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|