how to send parameter to codeunit?

bangswitbangswit Member Posts: 265
hi
how to send parameter to codeunit?
thanks

this is my code in codeunit

OnRun()
SalesInvLine.FINDFIRST;
SalesInvLine.SETRANGE(SalesInvLine."Sell-to Customer No.");
SalesInvLine.SETRANGE(SalesInvLine."Document No.",Parameter);
SalesInvLine.FINDSET;

Comments

  • lvanvugtlvanvugt Member Posts: 774
    Make sure you declare the Parameter variable global in that codeunit.
    Next declare a variable that's linked to your codeunit: MyCodunit
    Create a function in the same codeunit called, for example, SetParameter:
    SetParameter(par : <datatype of Parameter>)
    Parameter := par;
    
    Before you call the (OnRun) of the codeunit first call your new function SetParameter:
    MyCodeunit.SetParameter(<fill in the value you want to hand over to Parameter>);
    MyCodeunit.RUN;
    
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • AndwianAndwian Member Posts: 627
    bangswit wrote:
    how to send parameter to codeunit?

    Is it standard Codeunit or your custom made codeunit?

    If it is the standard CU, I prefer the one suggested by Luc:
    If
    lvanvugt wrote:
    Create a function in the same codeunit called, for example, SetParameter:
    SetParameter(par : <datatype of Parameter>)
    Parameter := par;
    

    Before you call the (OnRun) of the codeunit first call your new function SetParameter:
    MyCodeunit.SetParameter(<fill in the value you want to hand over to Parameter>);
    MyCodeunit.RUN;
    

    But if you use your own design CU, you can try this one:
    1. Add the Parameter to the CU.
    2. Run the CU with the passed parameter.
    Regards,
    Andwian
  • SLF25SLF25 Member Posts: 37
    Andwian wrote:
    But if you use your own design CU, you can try this one:
    1. Add the Parameter to the CU.
    2. Run the CU with the passed parameter.

    I think this is not possible, you have to create a function.
  • AndwianAndwian Member Posts: 627
    SLF25 wrote:
    Andwian wrote:
    But if you use your own design CU, you can try this one:
    1. Add the Parameter to the CU.
    2. Run the CU with the passed parameter.

    I think this is not possible, you have to create a function.
    oops.. thank you for pointing this out.

    I forgot that on OnRun() trigger, we could not add the parameter :mrgreen:
    Regards,
    Andwian
  • BeliasBelias Member Posts: 2,998
    edited 2010-08-25
    Andwian wrote:
    SLF25 wrote:
    Andwian wrote:
    But if you use your own design CU, you can try this one:
    1. Add the Parameter to the CU.
    2. Run the CU with the passed parameter.

    I think this is not possible, you have to create a function.
    oops.. thank you for pointing this out.

    I forgot that on OnRun() trigger, we could not add the parameter :mrgreen:
    not correct, we can add a record parameter (see codeunit 80, it's tableno property of the codeunit)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    that's right
    just like this
    CurrForm.SETSELECTIONFILTER(SalesInvHeader);
    REPORT.RUN(50092,TRUE,FALSE,SalesInvHeader);
    
  • BeliasBelias Member Posts: 2,998
    bangswit wrote:
    that's right
    just like this
    CurrForm.SETSELECTIONFILTER(SalesInvHeader);
    REPORT.RUN(50092,TRUE,FALSE,SalesInvHeader);
    
    :-k where's the codeunit?you said you want to pass a parameter to a codeunit, isn't it?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • AndwianAndwian Member Posts: 627
    Belias wrote:
    not correct, we can add a record parameter (see codeunit 80, it's tableno property of the codeunit)
    But we could only add ONE parameter, which is REC, isn't it?
    Bangswit wrote:
    that's right
    just like this
    CurrForm.SETSELECTIONFILTER(SalesInvHeader);
    REPORT.RUN(50092,TRUE,FALSE,SalesInvHeader);
    
    Isn't it a REPORT, instead of CU?
    Regards,
    Andwian
  • BeliasBelias Member Posts: 2,998
    Andwian wrote:
    But we could only add ONE parameter, which is REC, isn't it?
    just one, just rec, just "VAR" :mrgreen:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    Andwian wrote:
    Belias wrote:
    not correct, we can add a record parameter (see codeunit 80, it's tableno property of the codeunit)
    But we could only add ONE parameter, which is REC, isn't it?
    Bangswit wrote:
    that's right
    just like this
    CurrForm.SETSELECTIONFILTER(SalesInvHeader);
    REPORT.RUN(50092,TRUE,FALSE,SalesInvHeader);
    
    Isn't it a REPORT, instead of CU?

    owww yeah sorry i forgot to tell
    i change from codeunit become report
    because the client doesn't have codeunit
  • AndwianAndwian Member Posts: 627
    Belias wrote:
    we can add a record parameter (see codeunit 80, it's tableno property of the codeunit)
    Anyway, I just known this from you. Thanks anyway, Marko! :mrgreen:
    Regards,
    Andwian
  • BeliasBelias Member Posts: 2,998
    Andwian wrote:
    Belias wrote:
    we can add a record parameter (see codeunit 80, it's tableno property of the codeunit)
    Anyway, I just known this from you. Thanks anyway, Marko! :mrgreen:
    Mirko, not Marko! :mrgreen: anyway, you're welcome!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • AndwianAndwian Member Posts: 627
    Belias wrote:
    Mirko, not Marko! :mrgreen: anyway, you're welcome!
    Ooops... I am sorry :mrgreen: It is easier to just call Belias
    Regards,
    Andwian
Sign In or Register to comment.