Select a certain function

einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
Is there any dodge to create a setup where you can choose a certain function?
I know you can use
CODEUNIT.RUN(SetupTable."Codeunit No.",Rec)
but I have many, many setup records and I don't want to create as many codeunits. And no one wants to pay for such many codeunits.
"Money is likewise the greatest chance and the greatest scourge of mankind."

Comments

  • garakgarak Member Posts: 3,263
    only an idea. Do you checkt RecRef :?:
    One CU -> Parameter is RecRef .....
    Do you make it right, it works too!
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    garak wrote:
    only an idea. Do you checkt RecRef :?:
    One CU -> Parameter is RecRef .....

    Not possible with RecordRef .. I mean not possible to have codeunit with RecordRef as a parameter. Codeunits accept only records as a parameters - you can set only TableNo property.

    That would be very nice feature....

    As a workaround you may create new table to use it as some kind of 'code redirector', but hard-coding function names would e necessary at the end..

    Or create a function inside codeunit with RecordRef as a parameter, but then CODEUNIT.RUN(number, RecRef) is not possible, rather CodeunitVariable.SomeSetupFunction(RecordRef)

    Regards,
    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • garakgarak Member Posts: 3,263
    i know, that it is not possible to create a CU with parameter RecRef.
    What i mean is a CU with a function and this function has RecRef as parameter .....
    Do you make it right, it works too!
  • garakgarak Member Posts: 3,263
    oh, i see
    One CU -> Parameter is RecRef .....
    i've forgotten to type
    One CU -> New Function -> Parameter is RecRef ....
    

    So, its true, nobody can understand me

    8-[
    Do you make it right, it works too!
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Hmmm, I don't know if it's clear what I mean. :?:
    I don't want to run a codeunit with RecRef. I try to give an example...

    Table 50000 Data
    Field 1|Category|Value
    12345|A_______|15
    12341|B_______|28

    Table Setup
    Category|CU No.
    A______|50000
    B______|50001
    C______|50002

    CU 50000 with TableNo 50000 (Rec Data)
    OnRun()
    Value := Value * 5;
    MODIFY;
    
    CU 50001 with TableNo 50000 (Rec Data)
    OnRun()
    Value := Value * 12 - 14;
    MODIFY;
    
    CU 50002 with TableNo 50000 (Rec Data)
    OnRun()
    Value := (Value + 17) / 3;
    MODIFY;
    

    I want to create a solution where the user could specifiy which calulation the system should take on a certain category. (The calculation is more complax than this example, it's just to make it clear.)
    Now my problem is that I (or the user) have to create as many codeunits as different setup records are given. It would be better if the user could specify "Function No." instead of "Codeunit No.". The solution would need less codeunits and the license wouldn't need to be updated every time a new calculation would be added.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Why don't you write some math engine to parse and execute math formulas? Then you can store many different calculation formulas. It should be easy especially if there are constant number of record types and fileds you need to play with.

    Here is some example: http://www.mibuso.com/dlinfo.asp?FileID=820

    Hope this helps.

    Regards,
    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    It's not only about math formula calculation. It was only an example. There could be also codeunits that do other things, e.g.

    CU 50003 with TableNo 50000 (Rec Data)
    OnRun()
    CLEAR(LedgEntry);
    LedgEntry.LOCKTABLE;
    LedgEntry.FINDLAST;
    LedgEntry."Entry No." += 1;
    LedgEntry."Posting Date" := TODAY;
    LedgEntry.Category := Category;
    LedgEntry.Value := Value;
    LedgEntry.INSERT;
    
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • AlbertvhAlbertvh Member Posts: 516
    Hi

    Maybe another idea

    Create a codeunit and one specific function which accepts recref and tabled id
    call this function from your object and in this function have a case statement calling the specific other functions
    SetupFunction(RecRef,TableID)
    
    CASE TabledID OF
       DATABASE::"Sales Line" :
           BEGIN
               CallSalesFunc(RecRef);
           END;
       .
       .
       .
    END:
    



    Albert
  • awarnawarn Member Posts: 261
    Maybe I am thinking about this too simply.

    Add a new field to the record, called FunctionNumber.

    Set the field before passing the record into the codeunit.

    YourTable.FunctionNumber = 4;
    YourTable.MODIFY;
    CODEUNIT.RUN(50000,YourTable);

    //In codeunit 50000
    OnRun

    CASE YourTable.FunctionNumber of
    1: PostLine;
    2: CheckLine;
    3: CalculateSquareRoot;
    4: Function4;
    5: Function5;
    END;

    ?
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Yeah, somebody who understands me! :wink:

    I've had the same idea, but the problem is that the user will have to know which No. will execute which function. I thought of something that is more self-explanatory. E.g. if the user could see the name of the functions (MultiplyValueBy4, PostLine, GetAssignedEmployee,...) or anything else that would help to fill the setup table correctly.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
Sign In or Register to comment.