C/SIDE Tips&Tricks

Hi everybody, In march this year, Navision Switzerland started a little competition amongst Fin developers about the most usefull C/SIDE tricks. The result is nothing which would make an experienced Navision programmer jump out of the chair but nevertheless some of the tips might be useful, especially for newbies: — Cut&Paste in Source Expression — As you know, you can open the a List of C/AL Expressions with F5 on the SourceExpression Property. Unfortunately you cannot insert a variable directly in the SourceExpression by selecting a variable and pressing . However you can Copy the variable with Ctrl-C in the List and paste it with Ctrl-V in the SourceExpression property. Better than nothing. — Options — Let’s assume you defined a Field Layout: Option (Adress,Telephone,Statistics,Budget). In C/SIDE code you would access an option as e.g. Layout::Telephone Now, many days have passed, many bears have been drunk and you forgot the spelling of the options. What to do? Program (wrong by purpose) “Layout::x” and compile. The compiler now lists all possible options. You can also write “Layout::T” which the compiler will replace correctly with “Layout::Telephone” as there is only ONE option starting with ‘T’. — Insert Fields into Dataport — In a Dataport, on the Field Designer, open the field menu. Select the fields you want to add to your dataport from the field menu then click somewhere into the field designer window and the selected fields will be added. — Debugger: Find line which causes error — If you have an error in your program, you need to find the program line which causes the error. From the Debugger menu active the option “Active” and DEACTIVATE the option “Breakpoint on Triggers”. Then run your errournous code again and the debugger will stop at the line which causes you sleepless nights. — Dataport Requestform — By default, Dataports let you select the Import/Export filename. However, as soon as you use the RequestForm this Filename-Field disappears. If you want both, RequestForm and Filename do the following: 1) Define a global Variable “Test” 2) Insert a Textbox with SourceExpression “Test” 3) Set the AsistEdit property to “yes” 4) Assign ControlID “1” (one) to the Textbox! It only works with ID 1. 5) OnAssistEdit Trigger of Textbox insert the code: Currdataport.Filename := test; — Report: Print Options from Request Form — On the Request Form you define variables like layout, number of copies, etc. Now you want to print these options. Simply Copy/Past the fields from the RequestForm to the sections. It is also possible to copy/paste normal fields and even buttons from forms into the report sections. — Input Dialog — You need the user enters some parameters but you don’t want to create a form for it: Let’s ask for three dates within our codeunit: Var window : Dialog; BookingDate : Date; DocumentDate : Date; DeliveryDate : Date; EntryNo : Integer; NewEntryNo : Integer; Window.open (‘Booking Date #1#########’+ ‘Dok. Date #2#########’+ ‘Shipment Date #3#########’, BookingDate,DocumentDate,DeliveryDate); EntryNo := 0; NewEntryNo := 1; While (NewEntryNo > 0) and (EntryNo <> NewEntryNo) do begin EntryNo := NewEntryNo; Case EntryNo of 1 : NewEntryNo := Window.input(1,BookingDate); 2 : NewEntryNo := Window.input(2,DocimentDate); 3 : NewEntryNo := Window.input(3,DeliveryDate); end; end; window.close; if NewEntryNo = 0 then Exit; … continue code … Explanation: This routine allows the user to use the up/down- arrows and (Shift-)Tab to move between the field. Function window.input returns the number of the next Entry Field if the user uses an arrow or tab. It returns 0 if the user presses ESC and the same fieldnumber if the user presses ENTER. — Occurence of Variables — In Reports and Forms it’s sometimes difficult to find out where a Variable has been used. Two ways to solve that: 1) Export the object as Text file and search in an editor. 2) Rename the Variable form “MyVar” to “xxxMyVar” and try to compile. The compiler will find the first occurence for you. Change the variablename on this line to xxxMyVar and continue compiling. Repeat until no further compiler errors occur. — Report: Read-Ahead — Let’s assume you want to print a grouped list (e.g. Items grouped by vendor) where a new page per vendor should be started. The NewPagePerRecord property doesn’t work satisfactory as will print an empty page at the end of the report. Therefore you have to program the page-break manually according to the rule: “If Vendor changes, start a new page providing this is not the last page.” Section Items.GroupFooter.OnPresection Var I : Items; If CurrReport.TOTALSCAUSEDBY = FIELDNO(“Vendor”) Then Begin I.Copy(Items); If I.Next > 0 then CurrReport.NEWPAGE; end; — Delete Objects with Copy & Paste — In Object Designer you can delete a Form, Report, Dataport or Codeunit (doesn’t work with Tables) by selecting it and pressing Ctrl-C/Ctrl-V at the same place. The Original as well as the Copy is history. (Wonder why this guy doesn’t simply use F4, but ok) — Ok, folks that’s it. I hope you found something useful. Marcus Fabian ---------------------------------- fabian@ddag.ch m.fabian@thenet.ch 079 439 78 72 ---------------------------------- [/b]

— Report: Read-Ahead — Let’s assume you want to print a grouped list (e.g. Items grouped by vendor) where a new page per vendor should be started. The NewPagePerRecord property doesn’t work satisfactory as will print an empty page at the end of the report. Therefore you have to program the page-break manually according to the rule: “If Vendor changes, start a new page providing this is not the last page.” Section Items.GroupFooter.OnPresection Var I : Items; If CurrReport.TOTALSCAUSEDBY = FIELDNO(“Vendor”) Then Begin I.Copy(Items); If I.Next > 0 then CurrReport.NEWPAGE; end; ------- As i can see in the code he only wants to have a new page when changing the grouped field that is used… then the property NEW PAGE PER GROUP should work really fine :wink: BTW when having to break pages by record (and not needing the group field for other purposes) you can “fix” the last page bug by grouping by the key field and using the new page per group option (instead of new page per record). It works fine… only problem is when needing to use on a multiple fields key’s record… but it can be a easy and fast-non-code solution in a lot of times. Regards, Alfonso Pertierra apertierra@teleline.es

Maybe a Tips & Tricks section would be good for new and old Developers! I use use the NOT Statement for boolean Values It makes Cleaner Code IE: Instead of IF Customer.Blocked = FALSE THEN I use IF NOT Customer.Blocked THEN Switching the Boolean TRUE > FALSE or FASLE > TRUE by Customer.Blocked:=NOT Customer.Blocked; As in VB etc: Mr David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk

Instead of var := var + const you can write var += const; var := var - const you can write var -= const; var := var * const you can write var *= const; var := var / const you can write var /= const;

if you want to delete all Filters (which are saved automatically from NF) of every DataItem before the report start try this Customer.RESET; “Customer Ledger Entries”.RESET; “Customer Trial Bal.”.SETTABLEVIEW(Customer); “Customer Trial Bal.”.SETTABLEVIEW(“Customer Ledger Entries”); “Customer Trial Bal.”.RUN; NOTICE: you can use SETTABLEVIEW with a record of every DataItem from the Report its not the same but this works too: Report.RUN(104,Customer,TRUE,TRUE); Report.RUN(104,“Customer Ledger Entries”,TRUE,TRUE); But this starts the report twice :)…

If you want to find a function or a trigger in a object, you can scroll down until you find it. There is a faster way to do it. Select a trigger (mostly the Documentation trigger, becaurce this is the first one in a object) and then type the first character of the string you are searching. The cursor will jump to the funtion or trigger. Repeat this step(s) until you have the one you want to find. There is a exception however… If there are C/AL statements with the same first character, Navision will find those too. But this can make searching faster. Edited by - eromein on 8/17/00 1:49:24 PM Edited by - eromein on 8/17/00 1:50:24 PM