Custom Functions with OPTIONAL parameters?

abartonicek
Member Posts: 162
Can this be done?
Better to be critical then self-critical 

0
Comments
-
-
Who would need that, rightBetter to be critical then self-critical0 -
But there may be some work-arounds!
Please explain what it is you're trying to achieve.
Kind regards,
Jan Hoek
Product Developer
Mprise Products B.V.0 -
Some trick. It is a trick to emulate optional parameters.
1) Put your function that needs optional parameters in a codeunit.
2) Create 1 or more extra functions that can be called BEFORE your function to pass the optional parameters, then call the your function
eg. a function that adds lots of 2 or more decimals and gives the resultCODEUNIT START Function Add(IdecDecimal1 AS Decimal;IdecDecimal2 AS Decimal): OdecReturnValue As Decimal BEGIN OdecReturnValue := IdecDecimal1 + IdecDecimal2; tmpSomeTempTable.RESET; IF tmpSomeTempTable.FIND('-') THEN REPEAT OdecReturnValue += tmpSomeTempTable."Optional Decimal"; tmpSomeTempTable.DELETE(FALSE); UNTIL tmpSomeTempTable.NEXT = 0; END; Function AddOptionalDecimal(IdecOptionalDecimal As Decimal) BEGIN intUniqueEntry += 1; CLEAR(tmpSomeTempTable); tmpSomeTempTable."Entry No." := intUniqueEntry; tmpSomeTempTable."Optional Decimal" := IdecOptionalDecimal; tmpSomeTempTable.INSERT(FALSE); END; CODEUNIT STOP
How to use it:cduMyCodeunit.AddOptionalDecimal(4); cduMyCodeunit.AddOptionalDecimal(8); MESSAGE('Total = %1',cduMyCodeunit.Add(1,2));
Didn't test the code, so there can be some typo in it.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Hows this - create a new table, each field in the table will be an optional parameter. The table does not need to be in the license range.
The table record is the only parameter in the function.
Fill the table record, DONT insert, but pass it into the function.
Within the function now some of the 'fields' in the table will be filled and some will not.
Short example:
New table:
Fields:
1 - Item No.
2 - Description
3 - Price
4 - Cost
5 - Salesperson
6 - Vendor
7 - etc...
Code to call function:
NewTable.init; (to clear out values)
NewTable.Item No. := '123456';
NewTable.Cost := 99.00;
NewTable.Vendor := =AAA';
NewFunction(NewTable);
The NewFunction looks like this:
One parameter, type NewTable
NewFunction(NewTable)
If NewTable.Price = 0 then begin
//conditional code here
end else if NewTable.Cost > 10000 then begin
//conditional code here
End else if...
-a0 -
Super TIP!
And if you make the table TEMPORARY you don't need to have it in the customer license
Or is this already handled by not inserting the record?0 -
I'm not sure - but making temporary is probably the best idea - I always wait until I see the error [-o<
-a0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions