Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Write method not called after click on save button

(0) ShareShare
ReportReport
Posted on by 163

First Q : I want to add validation before saving records in database but write method doesn't called and records save without getting the error message .

How to make write method called and records doesn't save if getting the errror ?

1715.Screenshot-_2800_34_2900_.png

second Q : 

I want to make priority field in table to be an auto increment and show automatic when click on add button so I wrote code on init value () datasource method and made a method on table but it gets the max priority on table not on table in this loan item . 

how to fix this ? 

3716.Screenshot-_2800_31_2900_.png0336.Screenshot-_2800_30_2900_.png2337.Screenshot-_2800_33_2900_.png

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Write method not called after click on save button

    Try adding the logic in leave method of LoanItem DataSource. Leave method will be called when you leave the current record.

    It will return a Boolean value. So, throw an error or warning if the ratio is less than 100.

    Thanks,

    Girish S.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: Write method not called after click on save button

    I get it . I will try to save data in temp table , which method can I do it before saving data ? , save data in temp table if no error insert data from temp

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: Write method not called after click on save button

    That returns as to my first reply. The method validating a record before saving is validateWrite().

    You rejected it with "but it return the error on record level not on all record"; it seems that you want to save records without a validation and runs a validation against saved records.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: Write method not called after click on save button

    which method can I used to run before saving records ?

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: Write method not called after click on save button

    You asked for running a validation at a point where records are already saved, so throwing an exception won't change what already happened.

    If you want users to insert several records, then run a validation and decide whether all the records should be saved in database or not, it means that you need to store the records somewhere else before the validation and copy them to DB if the validation succeeded. You can use a temporary table for that.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: Write method not called after click on save button

    I tried it on written () on data source it is running but save data even if throw error . can I make records don't save until click on save or save if it doesn't throw error ?

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Write method not called after click on save button

    I checked leave method on Grid - Leave method is called whenever we close this form - LostFocus method is never called.

    So, it's better to add the code in the form closed method and add the error message as per your scenario.

    Thanks,

    Girish S.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Write method not called after click on save button

    I am not sure why the leave and lost focus method doesn't get called.  Also try debugging the code.

    Do a find reference on the leave and lostFocus method and see whether this method was used in the standard logic.

    Thanks,

    Girish S.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: Write method not called after click on save button

    I want to validate records when I leave tab page that have grid .

    like leave of lost focus but It doesn't called .

    Do you know any ways to execute these method or why not called ?

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Write method not called after click on save button

    Try adding the validation logic in form Closed method. Closed method will have return type as Boolean.

    During closing of the form this method will be called. If you add code here it will check the condition - If it is false, then it won't allow you to close the form until the value is given as greater than 100.

    public boolean closed()
    {
        boolean ret;
        ret = next closed();
        // add select statement to get total allocation ration.
        if(allocationRatio < 100)
        {
            ret = checkfailes("Error message");
        }
        else
        {
            ret  = true;
        }
    }

    Check whether this work around suits your scenario,

    Thanks,

    Girish S.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans