Friday, August 5, 2016

Using With Statement in C/AL code | Make Code Simple Series

How to write lesser code in NAV...!!??!!

There is always a better way. I am fortifying my Programming skills everyday with some customized code. I like to make coding life interesting so i keep on making small changes to make life easier and programming more intelligent. 

I would like to share today about With Statement. When we work with records(except Current record 'rec'), addressing is created as record name, dot (period), and field name:

For example let say we are coding into Sales line table with 'Item' record. then we need to continuously use "Item.FieldName" and if we need to write code for ten or twenty fields or any field repeatedly then it makes no sense using Item(Dot) always. This is where we should know WITH STATEMENT. 

WITH <Record> DO
  "No." := '1234';         //Instead of Item."No."
  Description:= 'Pokemon GO Server';      //Instead of Item.Description
  "Unit Cost" := '50000.50';       //Item."Unit Cost"
//Other codes


No comments:

Post a Comment