web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / RabinsNAVBlog / Using With Statement in C/A...

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

Rabin Profile Picture Rabin 2,976
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. 


SYNTAX:
********
WITH <Record> DO
<Statement>
********
EXAMPLE:
********
WITH ITEM DO BEGIN
"No." := '1234'; //Instead of Item."No."
Description:= 'Pokemon GO Server'; //Instead of Item.Description
"Unit Cost" := '50000.50'; //Item."Unit Cost"
//Other codes
END;
*****

Ref: https://msdn.microsoft.com/en-us/library/dd338911.aspx 


This was originally posted here.

Comments

*This post is locked for comments