web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

How to read Data from SubForm

(0) ShareShare
ReportReport
Posted on by 3,099

Hi

  How to read Data from Subform and then insert record in Same SourceTable or another table.

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    What do you mean read the data from the subform ? From an action ? if so you need apply the same filters you have applied for subform link then get those records.

  • jsshivalik Profile Picture
    3,099 on at

    Hi

      https://imgur.com/scLGnHa

      I have Main Form (Location) & SaleDeposit SubForm (Source table is SaleDepositLines) . I have 1 Button . On Push Trigger of Button

    I want those lines  which have DepositAmount > 0 should be inserted in same table SaleDepositLines.  I am trying below code but not working

    CDLine refers to the same table which Subform refers to

    CDLine.RESET;

    CDLine.SETRANGE("Location.","No.");

    CDLine.SETFILTER("Deposit Amount",'<>%1',0);

    IF CDLine.FINDFIRST THEN BEGIN

    REPEAT

    CDLine.INIT;

    EntryNo := EntryNo + 1;

    CDLine.VALIDATE("Entry No.",EntryNo);

    CDLine.VALIDATE("Location","No.");

    CDLine.VALIDATE("Posted Amount", CDLine."Deposit Amount");

    CDLine.INSERT;

    UNTIL CDLine.NEXT = 0;

    END;

    Thanks

  • Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    Firstly why are you inserting the same records in the same table, and second your  filter CDLine.SETFILTER("Receipt Amount",'<>%1',0) is looking for the lines which are not equal to zero for greater then you need to use CDLine.SETFILTER("receipt amount",'>%1',0); then in your REPEAT loop you need use another variable to insert the lines not the same variable which are looping may be call it CDLine2 and decalare it.

  • jsshivalik Profile Picture
    3,099 on at

    Hi

     ok.  In my scenario i am using only 1 table. That's why i have to do like this . If i was using 2 tables then it should not have been any issue

    Thanks

  • Suggested answer
    Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    I am not asking to use two tables, create two different variables of the same table.  One for looping and another for inserting. You cannot use the same variable to create and find. It will remove the filters you have applied.

  • jsshivalik Profile Picture
    3,099 on at

    Hi Suresh

    I have change the code but it goes in infinite loop

    CDNLine.RESET;
    CDNLine.SETRANGE("Location","No.");
    IF CDNLine.FINDLAST THEN
    EntryNo := CDNLine."Entry No.";

    CDNLine.RESET;
    CDNLine.SETRANGE("Location","No.");
    CDNLine.SETFILTER("Receipt Amount",'>%1',0);
    IF CDNLine.FINDFIRST THEN BEGIN
    REPEAT

    EntryNo := EntryNo + 1;

    CDNLine1 := CDNLine;
    CDNLine1.VALIDATE("Entry No.", EntryNo);
    CDNLine1.VALIDATE("Location", "No.");
    CDNLine1.VALIDATE("Posted Amount", CDNLine."Receipt Amount");
    CDNLine1.INSERT;
    CDNLine.VALIDATE("Receipt Amount", 0);
    CDNLine.MODIFY;
    UNTIL CDNLine.NEXT = 0;
    END;

    Thanks

  • Suggested answer
    Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    You need to have a Boolean which you can set it to true once inserted into the table and while looping you will check only for false entries. Anyhow your logic of inserting the values into the same table based on a filter condition doesn’t make any sense.

    What is your actual requirement ?

  • jsshivalik Profile Picture
    3,099 on at

    Hi

    i have done like this . It is working Is it correct

    CDNLine.RESET;

    CDNLine1 := CDNLine;

    CDNLine.SETRANGE("Location","No.");

    CDNLine.SETFILTER("Receipt Amount",'>%1',0);

    IF CDNLine.FINDFIRST THEN BEGIN

    REPEAT

    EntryNo := EntryNo + 1;

    CDNLine1.VALIDATE("Entry No.", EntryNo);

    CDNLine1.VALIDATE("Location", "No.");

    CDNLine1.VALIDATE("Posted Amount", CDNLine."Receipt Amount");

    CDNLine1.INSERT;

    UNTIL CDNLine.NEXT = 0;

    END;

  • Suggested answer
    Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    What you are doing is just creating duplicate entries, your whole logic is wrong. You need to specify what is your actual requirement and what are you trying to accomplish? If you want to find the entries with receipt amount greater then zero then you can retrieve those using filters why are you inserting it again in the same table?

  • Suggested answer
    CDsilva Profile Picture
    4,188 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans