How “not” to increase the batch name


NAV standard, in the case of use of batch name containing numbers, after posting automatically increases the last number existing in batch name (example: Batch 1 > 2 ..AL110A > AL111A.. and so on..)

This functionality is handled “Bydesign” in NAV, if you want to “NOT increase” the number and keep the same number in the batch (example in the case of fixed batch used for example for output and consumption and related numbered machines, former assets) can modify the codeunit 23 “Item Jnl.-Post Batch”

To achieve this, you need to change this line ItemJnlBatch.Name: = INCSTR ( “Journal Batch Name”) in function HandleNonRecurringLine

Function HandleNonRecurringLine

(VAR ItemJnlLine: Record “Item Journal Line”; OldEntryType: ‘Purchase, Sale, Adjmt Positive., Negative Adjmt., Transfer, Consumption, Output,, Assembly Consumption, Output Assembly’)

Original Code
ItemJnlLine3.COPY (ItemJnlLine);
ItemJnlLine3.DELETEALL;
ItemJnlLine3.RESET;
ItemJnlLine3.SETRANGE ( “Journal Template Name”, “Journal Template Name”);
ItemJnlLine3.SETRANGE ( “Journal Batch Name”, “Journal Batch Name”);

IF NOT THEN ItemJnlLine3.FINDLAST
IF INCSTR ( “Journal Batch Name”) <> ” THEN BEGIN
ItemJnlBatch.DELETE;
ItemJnlBatch.Name: = INCSTR ( “Journal Batch Name”);
IF THEN ItemJnlBatch.INSERT;
“Journal Batch Name”: = ItemJnlBatch.Name;
END;

You can change code in this way … for example in case of Outputs Consumptions entries to post from machine from MES..
IF NOT (ItemJnlLine2. “Entry Type” IN [ItemJnlLine2. “Entry Type” :: Consumption, ItemJnlLine2. “Entry Type” :: Output]) THEN
..
//ItemJnlBatch.Name: = INCSTR ( “Journal Batch Name”); // OLD
ItemJnlBatch.Name: = “Journal Batch Name”; // NEW, maintain old batch name, don’t use INCRSTR statement
..

Nice post here on Mibuso about this issue.
Journal batch names post
http://forum.mibuso.com/discussion/44485/journal-batch-names

Advertisements

“How to” display picture from file in Item Picture Page


Below a short procedure to visualize a linked picture from a picture file (example file with “.GIF” extension) into the “Item Picture Page”.

The System load the image file in a BLOB field and after displays it on the picture page; at the close of the page the image is deleted from the item table in order to lighten the System; same procedure can be used in reports and can also be used in old versions of NAV… in this case NAV 2013.

imag1imgage2

image3.png

NAV C/AL Code

On Image Button of Item Card
// CHECK DATA IN RECORDLINK TABLE
RecordLink.RESET;
RecordLink.SETCURRENTKEY(Company,”Refer to”);
RecordLink.SETRANGE(Company,COMPANYNAME);
RecordLink.SETRANGE(“Refer to”,”No.”);
IF NOT RecordLink.FINDSET THEN EXIT;
FileToUpload := RecordLink.URL4;   //Custom field with link for image
IF FileToUpload = ” THEN EXIT;
//IMPORT IMAGE FROM FILE USING FILE MANAGEMENT
FileManagement.BLOBImportFromServerFile(recTempBlob,FileManagement.UploadFileSilent(FileToUpload));
ItemPicture.RESET;
ItemPicture.SETRANGE(“No.”,”No.”);
IF ItemPicture.FINDSET THEN BEGIN
ItemPicture.Picture := recTempBlob.Blob;
ItemPicture.MODIFY;
ItemPicture.RESET;
ItemPicture.SETRANGE(“No.”,”No.”);

// OPEN PAGE 346 Item Picture > Visualize Item Image
PagePicture.SETTABLEVIEW(ItemPicture);
PagePicture.RUN;
END;

//Image Cleaning
Page 346 Item Picture
OnClosePage()
itemPicture.RESET;
itemPicture.SETRANGE(“No.”,”No.”);
IF itemPicture.FINDSET THEN BEGIN
IF itemPicture.Picture.HASVALUE THEN BEGIN
itemPicture.CALCFIELDS(Picture);
CLEAR(itemPicture.Picture);
itemPicture.MODIFY;
END;
END;

“ALL About” C/AL Coding Guidelines


CAL

hi guys, this is another short post of my “ALL About” posts series (the first of this year); in this case i want to write about “C/AL Coding Rules and Guidelines”.

below a short list of documents\pages about this topic,

First “ALL IN ONE” Document but “ALWAYSuseful is:  “C/AL Coding Guidelines used at Microsoft Development Center Copenhagen”  …”The Bible” for each C/AL Developer!

Source: C/AL Coding Guidelines used at Microsoft Development Center

you can download PDF document here: cal-coding-guidelines-at-microsoft-development-center-copenhagen

“ALL IN ONE” Document Vs Wiki & Community Feedback Philosophy

CAL-Coding-Guidelines-at-Microsoft-Development-Center-Copenhagen.pdf” is “all in one document”. In contrast, on this wiki, the coding guidelines are published individually. The reason is: give you the chance to comment and share your oppinion on each one.

Question: Since we’re having the guidelines, how come there is still C/AL code in NAV which doesn’t respect them?

Answer: all new C/AL code is bound to follow the guidelines (else it cannot be checked-in). However, the code that existed before the rules – it does not. We had done cleanup in a certain degree. Now we’re gradually improving the old code base as we visit various objects in order to add new functionality, however chances are that code we didn’t touch in a long time had remained in its old form.

“Microsoft Dynamics Community is looking forward to your comments!  Where you can, do provide concrete examples of the alternatives, Good and Bad”

Wiki Page on Design Patterns

https://community.dynamics.com/nav/w/designpatterns/156.cal-coding-guidelines

other nice resources:

nice doc on Mibuso about “How to work with record-variables”:

http://mibuso.com/howtos/how-to-work-with-record-variables-version-2

Nice general sections on MSDN

General C/AL Programming Format

https://msdn.microsoft.com/en-us/library/ee414237(v=nav.10).aspx

Programming Best Practices

https://msdn.microsoft.com/en-us/library/ee414204(v=nav.90).aspx

C/AL Comments

https://msdn.microsoft.com/en-us/library/dd301180(v=nav.90).aspx

C/AL Coding Guidelines Video

“Scheduling Reports” option also available in report.RUNMODAL instead of report.RUN


Dynamics Product Suggestion | Microsoft Connect

“Scheduling Report” option also available in report.RUNMODAL instead of report.RUN

it would be useful to use the “report schedule” option also in report.RUNMODAL mode (in this mode is inhibited by design).
i can change the codeunit that launchs reports from “report selection” but  i think isn’t a good idea, i dont’ know why this feature is inhibited by design.

Source: “Scheduling Reports” option also available in report.RUNMODAL instead of report.RUN | Microsoft Connect

Load Data into NAV using C/AL and Powershell (SQL From NAV Part I)


Load Data into NAV using C/AL & Powershell

powershell cAL 

Sample Scenario

“Read distributed data from Sql Server and load a data warehouse using NAV C/AL with Powershell integration”

If you need to retrieve (and aggregate) data from more than ONE company or from more than ONE database , in NAV you can use “SQL Server Views” objects mapped as “NAV linked objects”.

… but if don’t want to use NAV Linked objects (SQL Tables or SQL View because is complex and time consuming to managing with many companies\many databases or because you don’t’ want to consume NAV tables for linked objects) and you don’t like “.net integrations” or utilization of external applications, you can use Powershell in NAV (and outside NAV certainly…)

You can achieve this goal using a Hybrid Methods to load data into NAV from different sources

  • Read data from Powershell
  • Write Data\Processing in NAV with C/AL Coding

You can use two functions by Waldo to do this:

  • Powershell Wrapper for NAV C/AL function
  • Invoke-NAVSQL function

Scenario

  • Use good Waldo function to launch powershell fro NAV (after this you can schedule on NAV NAS load data process) – PowerShell Wrapper
  • Read Sql Views from Powershell using Waldo Invoke-NAVSQL’ function
  • Write into NAV table using C/AL logic & data validations mixing C/AL and Powershell commands.

NB: Powershell consumes a concurrent user.

Details about these good functions by Waldo

“How-to” use powershell in NAV (NAV Powershell Wrapper)

“How- to” load data into NAV with Powershell? (Invoke-NAVSQL)

Example

Get all companies, and get the customers of the first company:

$Mycompanies = Invoke-NAVSql -ServerInstance ‘dynamicsNAV90’ -SQLCommand ‘Select * From Company’

$Customers = $Mycompanies |

select -First 1 |

foreach{ Invoke-NAVSQL -ServerInstance ‘dynamicsNAV90’ -SQLCommand “select * from [$($_.Name)$(‘$Customer’)]” -ShowWriteHost }

$Customers | select ‘No_’, Name, ‘Credit Limit (LCY)’ | Format-Table –AutoSize

ALL Source links:

http://www.waldo.be/2014/12/17/running-powershell-from-nav/

http://mibuso.com/downloads/running-powershell-in-nav

http://www.waldo.be/2016/06/08/invoke-navsql-execute-sql-queries-on-nav-databases-with-powershell/

https://github.com/waldo1001/Cloud.Ready.Software.PowerShell/blob/master/PSModules/Cloud.Ready.Software.NAV/SQL/Invoke-NAVSQL.ps1

Open Pages and Reports with filters using NAV Command lines


You can have directs shortcuts (or hyperlinks in your emails) to open directly pages & reports passing filters.
page2
Example (page):
– Base Command  dynamicsnav://server.local:port/Db/Company/runpage?page=9307
– Filter  parameter  $filter=%27Purchase%20Header%27.%27No.%27%20IS%20%27OF16000933%27
– View Mode  mode=View
Sample Full Command
dynamicsnav://server.local:port/Db/Company/runpage?page=9307&$filter=%27Purchase%20Header%27.%27No.%27%20IS%20%27OF16000933%27&mode=View
Results 
>  in this case system runs on NAV Client Page “9307 Order List” , the page is filtered on purchase Order No.’OF16000933
..you can build parametric strings to launch your pages\reports from command line (like existing features in NAV Approval Workflow).

RUNREQUESTPAGE, EXECUTE, PRINT, SAVEAS in NAV


…nice reporting functions are available from NAV 2015:  EX: RUNREQUESTPAGE, EXECUTE, PRINT, SAVEAS

MY BEST FUCTION IS:  “RUNREQUESTPAGE” -> This function lets you run a request page for a report, without actually running the report. When the user clicks OK, the function simply returns a text value, which is an XML document describing the user’s selection and filters of the request page.”; you can use this function also to schedule a report on Job Queue (OnDemand report schedule)

ex: a reports launcher page, scope of this page is run selected reports and generate PDF files after reports printing (or after preview mode report printing)

laucnher

The system use fiunction REPORT.RUNREQUESTPAGE to read and retrieve reports parameters

RUNREQUESTPAGE

XmlParameters:= REPORT.RUNREQUESTPAGE(intIDReport);

… after you get the following XML document as a result:

xml.png

EXECUTE

Now is time to run report with EXECUTE function. This function runs a report without showing a request page. It receives the parameters as an argument of type text, and you can feed the results of the RUNREQUESTPAGE to it. If the report you are executing is a processing-only report, then it will simply silently execute. If it’s a printable report, then it runs in the preview mode.

SAVEAS

SAVEAS function: “It does the same as SAVEASXML, SAVEASPDF, SAVEASEXCEL, and SAVEASWORD, only it does it without showing the request page”.

SOME EXAMPLES:

REPORT.RUNREQUESTPAGE

XmlParameters:= REPORT.RUNREQUESTPAGE(intIDReport);

// Use the REPORT.SAVEAS function to save the report as a PDF file

REPORT.SAVEAS (intIDReport,XmlParameters,REPORTFORMAT::Pdf,OStream);

// Use the REPORT.EXECUTE function to preview the report

REPORT.EXECUTE (intIDReport,XmlParameters);

// Use the REPORT.Print function to print the report

REPORT.PRINT (intIDReport,XmlParameters);

DEMO FUNCTION: “SaveReportPDF”

SaveReportPDF (intIDReport : Integer;txtNomeFile : Text;blnPreview : Boolean;blnPrint : Boolean;blnSavePDF : Boolean;txtPath : Text)

//DEMO .sn

// Use the REPORT.RUNREQUESTPAGE function to run the request page to get report   parameters

CLEAR(XmlParameters);

XmlParameters := REPORT.RUNREQUESTPAGE(intIDReport);

CurrentUser := USERID;

// Use the REPORT.SAVEAS function to save the report as a PDF file

IF blnSavePDF THEN

BEGIN

Content.CREATE(txtPath + txtNomeFile+DELCHR(FORMAT(CURRENTDATETIME,0,'<Day,2>-<Month,2>-<Year> <Hours24>.<Minutes,2>.<Seconds,2>’),’=’,’-:/. ‘)+’.pdf’);

Content.CREATEOUTSTREAM(OStream);

REPORT.SAVEAS(intIDReport,XmlParameters,REPORTFORMAT::Pdf,OStream);

Content.CLOSE;

MESSAGE(‘PDF File written > OK’);

END;

// Use the REPORT.EXECUTE function to preview the report

IF blnPreview THEN

REPORT.EXECUTE(intIDReport,XmlParameters);

// Use the REPORT.Print function to print the report

IF blnPrint THEN

REPORT.PRINT(intIDReport,XmlParameters);

//DEMO .en

Progress Indicator vs window


..nice old “but actual” post about NAV progress indicator !

progre

Example
Progress indicator based on Item DataItem
Create a report with Item as the dataitem.  
Put the code below in the prescribed triggers. 
Define the variables, Run the report  
The TotalCount will adjust per the filters you enter on the report so the 
progression bar is always on time.

Variables
Name         DataType
Window       Dialog  
TotalCount   Integer  
Counter      Integer  
  
Item - OnPreDataItem()
  Window.OPEN('Processing: @1@@@@@@@@@@@@@@@');
  TotalCount := COUNT;
Item - OnAfterGetRecord()
  Counter := Counter + 1;
  Window.UPDATE(1,ROUND(Counter / TotalCount * 10000, 1));
   
Item - OnPostDataItem()
  Window.CLOSE;

How-to use Dialog Box with Progress Indicator
Try using a dialog box, but instead of using (ex. '#1######') you use 
(ex. @1@@@@@@@@@@@@@). The "@" sign signifies that you want to use 
progress bar indicator.

Source http://groups.yahoo.com/group/Navision-Knowledge-Village/

Sharing the knowledge on Navision > Visit www.frappr.com/navision for navison friends 
http://groups.yahoo.com/group/Navision-Knowledge-Village/

based on this question :
"When running a long processing report, I usually open a window & 
update it with the entry no I am processing. Instead of using this, is 
there a function that can create a progress indicator type bar instead 
with a % done (for example, like the one you see when importing a file)?"

C/AL Editor, Development Environment and Windows client Keyboard Shortcuts in NAV 2016 – Jatin Patel – Microsoft Dynamics NAV


Nice post by jatin Patel – reblogged

Source: C/AL Editor, Development Environment and Windows client Keyboard Shortcuts in NAV 2016 – Jatin Patel – Microsoft Dynamics NAV

Best news and features about NAV 2016 C/AL code editor


Best news and features about NAV 2016 C/AL code editor

NAv 2016 code

With NAV 2016 have been added these new features:

  • Line numbers & syntax highlighting 
  • Indicators notifications, a yellow line indicates the lines of code that have been changed but not yet saved. After saving the object, the line is green. (Like .VB net, C# Net & SQL Server Editor Technology)
  • Intellisense  wirh autocompletion of code. Intellisense technology greatly simplifies life for developers, which can save time and reduce writing errors.
  • Undo,  The combination of CTRL + Z is now also active in the editor of NAV, allowing you to undo any changes to the code.

good.