Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Inserting From a page to a table

(0) ShareShare
ReportReport
Posted on by

Hi everyone, am trying to insert a candidate info to my employee table when the status is changed to hired but it is not inserting the new record. I put the codes on page action but i don't know why is not working. 


IF Status = Status :: Hired THEN BEGIN
Employee.INIT;
Employee."No." := 'PC037';
Employee."First Name" := "First Name";
Employee."Middle Name" := "Middle Name";
Employee."Last Name" := "Last Name";
Employee."Job Title" := "Job Title";

Employee.INSERT;
END
ELSE BEGIN
MESSAGE('THIS IS NOT INSERTING');
END;

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Inserting From a page to a table

    Thanks for your answers it works

  • Verified answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Inserting From a page to a table

    If you want to  create a new employee every time the status is changed to hired then check the customer table onInsert trigger add the similar code like that to assign no. to the employee using no. series and in your code execute don't assign no. value and execute

    Employee.INSERT(TRUE)

  • Community Member Profile Picture
    on at
    RE: Inserting From a page to a table

    I already have the NoSeries for the employee, it is working as i want it to be but i don't want it to modify the existing record

  • Community Member Profile Picture
    on at
    RE: Inserting From a page to a table

    Suresh it is working but i don't want it to modify the existing record, i want it to start from the last number in the employee table

  • Community Member Profile Picture
    on at
    RE: Inserting From a page to a table

    I think you should setup a new no series for your employees if you want to add new ones like this and use this code to get the next number from the number series:

    Employee."No." := NoSeriesMgt.GetNextNo('YourNewNumberSeriesCode',WORKDATE,TRUE);

    NoSeriesMgt Variable

    Name DataType Subtype

    NoSeriesMgt Codeunit NoSeriesManagement

  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Inserting From a page to a table

    you will get that error if the record exist you need to change your last statement like this 

    IF NOT Employee.INSERT THEN

    Employee.MODIFY;

    or

    the first initial statement to execute only if the record does not exist

    IF (Status = Status :: Hired) AND (NOT Employee.GET("Candidate No.")) THEN BEGIN

  • Community Member Profile Picture
    on at
    RE: Inserting From a page to a table

    It is executing but i think I need a command that increment from the last record. see below error

    5265.snapshot.PNG

  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Inserting From a page to a table

    You need to click the action to execute the trigger, if you want to execute the code when the status is changed then you need to move your code to onValidate trigger of that field on the page or on the table. I recommend moving your code to the onvalidate of the field on the table.

  • Community Member Profile Picture
    on at
    RE: Inserting From a page to a table

    I just did

  • Tharanga Chandrasekara Profile Picture
    23,116 on at
    RE: Inserting From a page to a table

    Can you post the screenshot with the trigger header?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans