Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Action entering same value for all records with Action on List Page- BC Dev

Posted on by 65

Screenshot-2022_2D00_12_2D00_22-023131.pngScreenshot-2022_2D00_12_2D00_22-024503.pngScreenshot-2022_2D00_12_2D00_22-024438.png

This is for developers to take a look at and see if they have encountered this problem. Long story short, I have this action on the list page for the Warehouse Picks (Warehouse Activity header table) and when using this code for the onaftergetrecord trigger it works just fine, but when using it for an action on the list page, it does not work the same. This issue doesn't arise when you can use the onaftergetrecord trigger like I mentioned, but in this case I need to use an action to actually enter the data into the fields, which is why this is an issue..

Anyways, what it SHOULD be doing (imo) is going through each record in the WAH, and doing the calculation for the respective record (like it does for the onaftergetrecord trigger). Instead, with an action, it is using the record that is highlighted on the page, and then the value for each record then is based on the record highlighted, not the respective record. 

Any ideas would be appreciated on how I could the get the WAL No. to be filtered based on the respective record WAH No., not just filtering the WAL No. with the same WAH No. that is selected on the page. I've done this plenty of times with similar requirements, but this one is a little trickier when it shouldn't be..

Thanks.

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,186 Super User on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    hi

    when I say this:

    "if you want to do it from an action you have to create a field in the WAH and value it with the action"

    it was sub-understood that to value a table field you have to do the MODIFY

    DAniele

  • Suggested answer
    pankaj.k Profile Picture
    pankaj.k 960 on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    Hi AGV,

    Try with below code...

                    trigger OnAction()
                    var
                        WAH: Record "Warehouse Activity Header";
                        WAL: Record "Warehouse Activity Line";
                    begin
                        WAH.Reset();
                        if WAH.FindFirst() then begin
                            WAL.Reset();
                            if WAL.FindFirst() then begin
                                repeat
                                    WAL.CalcSums(Quantity);
                                    Test := WAL.Quantity;
                                    WAL.Modify();
                                until wal.Next() = 0;
                            end;
                        end;
                        CurrPage.Update();
                    end;
  • AGV Profile Picture
    AGV 65 on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    What you did not mention is adding the WAH.Modify() procedure to the end of the code. I mentioned that in my last reply, but that was the missing piece to the code, and why it was not calculating correctly.

    I tried many variations before taking the original screenshot of my code, and I already tried the way you suggested, WAL.setrange("No.", WAH. "No."), and then using table field instead of a global variable. I just used the global variable when re-writing the code to see what changes would happen, if any.

    To anyone reading this in the future, this missing piece was the WAH.Modify() at the end (as I mentioned when saying I did that for the OnAfterGetRecord, and the calculations were showing correctly on the page, and then it inserted the data into the table fields).  

    See below for how you should code this if you run into this. Hope this helps:

    Screenshot-2022_2D00_12_2D00_22-044628.png

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,186 Super User on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    Listen I see two problems in your code on the action.

    The first is that you have to replace:

    wal.setrange("No.",Rec. "No.") to Wal.setrange("No.",Wah. "No.")

    the second is that if you value the variable Test with an action on the page you will obviously have the calculation of the last WAL. Whereas on the other hand it obviously fuzniona onaftergetrecord xbecause it is calculated for each row.

    if you want to do it from an action you have to create a field in the WAH and value it with the action

    DANiele

  • AGV Profile Picture
    AGV 65 on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    I meant it doesn't calculate *correctly*. It also was entering the same value for every record, and not calculating the total quantity for the WAL based on the respective WAH No. it should've been filtering on, per record.

    Anyways, I found another solution using the OnAfterGetRecord, and added Rec.Modify() to the end of the code, which entered the data into the table fields.

    If you can figure out how to write the code for the Action and make it work, feel free to share.

    Thanks

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 20,991 Super User on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    share your code in txt format.

  • AGV Profile Picture
    AGV 65 on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    I already tried that, doesn't calculate values for any of the records with that syntax

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 20,991 Super User on at
    RE: Action entering same value for all records with Action on List Page- BC Dev

    Hi,

    ALWAYS PUT CODE IN TEXT FORMAT NOT IN IMAGE FORMAT.

    you can replace your line wal.setrange("No.",Rec."No.") to Wal.setrange("No.",Wah."No.");

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans