Need help with Rec (Trying to define and Rec to Release Pur)

Doc9Doc9 Member Posts: 26
Hi, I’m a newb so bear with me. I have been certified dev 1/2 fin 1/2 and sql so I have a good heads up I just write most of my code in web based languages and vb.

That aside here is my simple problem. BTW I have searched and research to no avail.

I have a form that is used with touch screens (big buttons and texts) which is simply filtering and color coding the purchase order lines table data. That’s all the form displays, it’s the same form as Purchase Order Lines.

The shop guys update the qty's to receive. They also update total qty when > than qty to receive.

When doing this (as we always release our documents) they will need to update / release and reopen the purchase document from one button. The recursion required for this I can handle. Its passing finding and passing the Purchase Header Rec from my Purchase Lines to code unit 415-Release Purchase Document that has me confused.

I have looked into the Release Purchase Document Code Unit (415) and can see the two functions which require you to pass Rec and a parameter. This is fin except i have now broken two keyboards in half over this error i get often. Variable must belong to 38 not 0 or if I change variables I get must belong to 38 and not 39.

I know I am failing to program the Rec correctly. I don’t know how to tell the push action or the code (ReleasePurchDoc.PerformManualRelease(Rec);) that Rec is the document number from the currently selected line.


Please any help would do.
Thank you...

Comments

  • ssinglassingla Member Posts: 2,973
    Doc9 wrote:
    I know I am failing to program the Rec correctly. I don’t know how to tell the push action or the code (ReleasePurchDoc.PerformManualRelease(Rec);) that Rec is the document number from the currently selected line.

    Rec is the record variable and not the document number
    CA Sandeep Singla
    http://ssdynamics.co.in
  • DenSterDenSter Member Posts: 8,304
    Rec points to the source table of the main form. If your form is based on purchase line, then you will need to get the purchase header that belongs to the line, and send that into the release codeunit.
  • ShedmanShedman Member Posts: 194
    You could try 2 things:
    1. The SETSELECTIONFILTER function (see the Help file)
    2. Create a new Purchase Line record variable and set ranges and filters on it so it gets you the current record
  • Doc9Doc9 Member Posts: 26
    I am fully aware of what Rec is and how to pass it when needed from the active form. What the problem consists of is setting rec on the purchase header from the purchase line which is in my form so that i may send to cu-415 the rec for the Purchase Header based on my selection from the lines in my form.


    I have in my Dev books, online help, dynamics user, dynamics partner source and here looked for information and can not find it.

    Simple View
    Purchase order lines form, design and save it as something else.

    Now goto the purchase order, design and take this code and setup variables;
    You will get somethine like this (ReleasePurchDoc.PerformManualRelease(Rec);).

    Now go back to your Purchase Order Lines form and create a button, setup variables, add code.


    See below for a clear cut example of what i am trying todo and the area where I am experiancing a problem in defining rec for the header table.
    (BWT I know about Table := Rec;, does not work. Rec inherited by form)

    Rec is now = Rec for purchase lines, duh know this.
    {

    Example Code

    ON PUSH()

    ?¿¿? MISSING CODE TO DEFINE REC FOR OR FROM PURCHASE HEADER!!! ¿??¿

    PoNum := Rec."Document No."
    SETRANGE(PurchaseHeader."No.", "PoNum");

    IF (PurchaseHeader.Status = PurchaseHeader.Status::Released) THEN BEGIN
    ReleasePurchDoc.PerformManualRelease(Rec);
    END;

    IF (PurchaseHeader.Status = PurchaseHeader.Status::Open) THEN BEGIN
    ReleasePurchDoc.PerformManualOpen(Rec);
    END;
    }

    So I’m sure this is an easy thing I just lack experience and am having a lot of trouble finding answers on my own.
  • Doc9Doc9 Member Posts: 26
    Ok so reading though my posts seems like i am over complicating things.

    I am running my code from a from thats source table is Purchase Order Lines. So my Rec is related to purchase order lines.

    I need to use Code Unit 415 - Release Purchase Document to allow a button to change the status. I have to pass the function the Rec. This is the problem. Rec = Purchase Order Lines not Purchase Header.

    How can I pass Rec to the functions within Code Unit 415 - Release Purchase Document when current Rec is Purchase Order Lines. How do I pass the code unit's function Rec from the Purchase Lines when the code unit requires Rec from the header?
  • DenSterDenSter Member Posts: 8,304
    Doc9 wrote:
    I am fully aware of what Rec is and how to pass it when needed from the active form
    I'll repeat it:
    DenSter wrote:
    If your form is based on purchase line, then you will need to get the purchase header that belongs to the line, and send that into the release codeunit.
    It looks like you are using a form based on the purchase line table, but the function you are trying to use, needs a purchase header record. If you are passing a line into a function that needs a header, I would dare to guess you are not so fully aware after all.

    So all sarcasm aside :mrgreen: (all in good jest on my part)

    Create a record variable based on the purchase header table, for instance "PurchaseHeader". The Purchase Line's primary key is (Document Type, Document Number, Line Number), and the first two fields are the primary key of the purchase header table. So, you can do:
    PurchaseHeader.GET(Rec."Document Type",Rec."Document No.");
    
    And that will retrieve the header that belongs to the line.

    Now lucky for you, the Purchase Line table has a function called "GetPurchHeader", which retrieves the header record for you, and stores it into the PurchHeader variable. So, you could even call that function right from your form, and pass the purchase header variable into the function.
  • Doc9Doc9 Member Posts: 26
    Have not tried it yet but U the man. When i stated i know about rec i ment using it on a form and understanding when to call or filter with it. I have however never tried to use or relate rec with out the form that is defining rec for me.
  • DenSterDenSter Member Posts: 8,304
    Look at Rec as just another record type variable, it's just not defined in the globals or locals. Anything you can do with any record variable, you can also do with Rec. The tricky part is that on every form, it stands for a different subtype, which is defined by the source table.

    Just be aware which record is actually stored in Rec, which is always the record that the user's cursor is currently on. In a Card form it's the record currently displayed, and in a list form it's the record that has the little triangle or asterisk next to it. You don't need to retrieve it from the database, because the form already did that for you.
  • DenSterDenSter Member Posts: 8,304
    By the way, to make sure you program the logic on your button in the same way as standard NAV, take a look at the code on the standard Purchase Order form, the Release selection of the Functions button. You could copy that code right into your button, and all you'd need to do is retrieve the header record (hint: use GetPurchHeader), that the code is looking at the PurchHeader variable and that you pass that record into the release codeunit.

    No need to re-invent the wheel. The goal is to get really good at knowing where to steal code snippets from the standard application :mrgreen:
Sign In or Register to comment.