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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Refresh Form Data Source After Delete, Write From Table

(0) ShareShare
ReportReport
Posted on by 1,214

Hi,

I'm working on Expense Reports (TrvExpenses) form.

Our requirement is:

When Map to travel requisition field is modified, we need to delete the Expenses lines, then replace the lines with records from Travel requisition lines. User will need to update Financial dimensions values afterwards.

trvexpenses.png

Expense report header (TrvExpTable) has a method called changedRequisition(), which is by default being called when Map to travel requisition is modified. So we extended this method and implement our delete & insert logic here in this table method.

For the form refresh, we tried calling formrun.Task(#taskRefresh) method in form OnActivated event.

The refresh works.However, form OnActivated is being triggered too often, and this is blocking user from navigating to Financial dimensions tab. Every time we try to click on Financial dimension tab, the form OnActivated is triggered and then we lost focus.

Then we tried calling TrvExpTable_ds.research(), TrvExpTrans_ds.research, TrvExpTable_ds.ExecuteQuery(), TrvExpTrans_ds.ExecuteQuery(), but all in vain.

trvexpenses-error.png

The lines are not refreshed at all. Need to refresh browser only then we can see the changes.

trvexpenses-ref.png

How can we achieve this requirement? Please help me with more ideas.

Thank you.

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Hairul,

    Why don't you do a data source reread and executeQuery() right after the changeRequition() method changes.

    You can also try to this on the datasource field modified as well.

    TrvExpTrans_ds.reread();
    TrvExpTrans_ds.ExecuteQuery();

  • HAIRUL HAZRI Profile Picture
    1,214 on at

    Hi Gunjan,

    thank you for your suggestion. It brings me to the right direction.

    Here's what I did. I added the form refresh task in changeRequisition() method:

    // hairul Test
    if(this.isFormDataSource())
    {
        fds = this.dataSource() as FormDataSource;
        
        if (fds)
        {
            fn = fds.formRun().name();
            formRun = fds.formRun();
            formrun.task(#taskRefresh);
            //fds.research();
        }
    }

    Travel Requisition Amount is not stored in table too, so need to refresh the form control manually:

    [ExtensionOf(formControlStr(TrvExpenses, MapTravelRequisition))]
    final class TrvExpenses_MapRequisition_Extension
    {
        //hairul test
        public boolean modified()
        {
            boolean ret;
            FormRun formrun;
            Form form;
            FormStringControl TravelRequisitionAmount;
            TrvRequisitionNumber                trvReqNumber;
            TrvExpTable trvExpTable;
            TrvExpTrans trvExpTrans;
            FormDataSource TrvExpTable_ds, TrvExpTrans_ds;
    
    
            ret = next modified();
            
            
            trvReqNumber = this.text();//MapTravelRequisition.text();
            formrun = this.formRun();
            
            TravelRequisitionAmount = formrun.design().controlName("TravelRequisitionAmount");
            
            TrvExpTable_ds = formrun.dataSource("TrvExpTable");
            //TrvExpTrans_ds = formrun.dataSource("TrvExpTrans");
    
            trvExpTable = TrvExpTable_ds.cursor();
            //trvExpTrans = TrvExpTrans_ds.cursor();
            
            
            TrvExpTable_ds.research();
            
            //********** Refresh TravelRequisitionAmount control
            TrvRequisitionTable trvRequisitionTable = TrvRequisitionTable::findByRequisitionNumberAndCompany(trvReqNumber, CompanyInfo::findDataArea(trvExpTable.InterCompanyLE).RecId);
            TravelRequisitionAmount.text(TrvExpenseHelper::amountWithCurrencyCode(trvRequisitionTable.totalEstimate(), trvRequisitionTable.LegalEntity));
                
            return ret;
        }
    
    }

    This seems working as required. Cheers :)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans