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, ...
Suggested Answer

Updating vendor bank account from Employee self service

(0) ShareShare
ReportReport
Posted on by 465

Hi,

I want when we insert a new account bank account where the Remainder is ticked to true or if the amount >0 in Employee self service-- then update vendor bank account related to the account.
 
The things is PayrollBankAccountDisbursement gets inserted after  HcmWorkerBankAccount. So how i'm going to check the  Remainder/amount values in PayrollBankAccountDisbursement 

[ExtensionOf(tableStr(HcmWorkerBankAccount))]
final class HcmWorkerBankAccountTable_Extension
{

    public void insert()
    {
        next insert();

        if(this.check())  /// how to do the check heree?? as i don't have the remainder and amount values
        {
            this.createOrUpdateVendBank();
        }
    }
    
        public void update()
    {
        next update();

        if(this.check())
        {
            this.createOrUpdateVendBank();
        }
    }
}


pastedimage1670236152308v1.png  

pastedimage1670236203709v3.png

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    So, you will be giving the bank account, amount and Remainder on the above form you have posted?

    So that is the case you can write the logic in the "What is your bank account" form itself right?

    You can utilize closeOk of the form to get the values- check the amount and remainder values >> Based on that update the account.

    Thanks,

    Girish S.

  • D365FO user Profile Picture
    465 on at

    Hi Girish,

    I updated the code above...

    shouldn't the code be in the table i want to work like that also from table level

  • GirishS Profile Picture
    27,827 Moderator on at

    What is the use of the form you have posted above?

    Can you elaborate more on this then we will decide where to write the code.

    Thanks,

    Girish S.

  • D365FO user Profile Picture
    465 on at

    Hi Girish,

    The self service should just be for the employee to amend their own details.

    So do you think form is enough? not sure if there could be a case in the future.

    Should it be on closeOk or Ok clicked method?

  • GirishS Profile Picture
    27,827 Moderator on at

    You need to write your logic in closeOk method. So, this method will be called after closing the form without any errors. This method is available at form level.

    Thanks,

    Girish S.

  • D365FO user Profile Picture
    465 on at

    Would the whole process fail if the logic i will put in close ok fail?  because it should

  • GirishS Profile Picture
    27,827 Moderator on at

    First you try to add the logic in closeOk and check whether it fulfill your requirement.

    Thanks,

    Girish S.

  • D365FO user Profile Picture
    465 on at

    Hi Girish,

    My logic worked, but if there are any errors with updating the vendor bank, then it will still create the bankAccount.

    So I'm assuming i need to change the logic place

    Would the OKButton be a good place? or can i do it on table level?

    [ExtensionOf(formStr(ESSDirectDepositEntry))]
    final class ESSDirectDepositEntry_Extension
    {
        public void closeOk()
        {
            FormDataSource payrollBankAccountDisbursementDS = this.dataSource(formDataSourceStr(EssDirectDepositEntry, PayrollBankAccountDisbursement));
            PayrollBankAccountDisbursement payrollBankAccountDisbursement = payrollBankAccountDisbursementDS.cursor();
            if(payrollBankAccountDisbursement.IsRemainder == NoYes::Yes)
            {
                FormDataSource hcmWorkerBankAccounttDS = this.dataSource(formDataSourceStr(EssDirectDepositEntry, HcmWorkerBankAccount));
                HcmWorkerBankAccount workerBankAccount = hcmWorkerBankAccounttDS.cursor();
                ttsbegin;
                this.createOrUpdateVendBank(workerBankAccount);
                ttscommit;
            }
            next closeOk();
        }
        
         private void createOrUpdateVendBank(HcmWorkerBankAccount _workerBankAccount)
        {
            HcmWorker       worker = HcmWorker::find(_workerBankAccount.Worker);
            VendTable       vendTable = VendTable::findByPartyRecId(worker.Person, true);
            VendBankAccount vendBank;
    
            if(vendTable)
            {
                select firstonly forupdate vendBank where vendBank.VendAccount == vendTable.AccountNum;
    
                PayrollBankAccountDisbursement payrollBankAccountDisbursement;
    
                select firstonly payrollBankAccountDisbursement
                where payrollBankAccountDisbursement.WorkerBankAccount == _workerBankAccount.RecId;
    
                if (vendBank.RecId == 0)
                {
                    vendBank.initValue();
                    vendBank.AccountID    = _workerBankAccount.AccountId;
                    vendBank.VendAccount  = vendTable.AccountNum;
                }
    
                vendBank.AccountID          = _workerBankAccount.AccountId;
                vendBank.AccountNum         = _workerBankAccount.AccountNum;
                vendBank.BankAccountType    = _workerBankAccount.BankAccountType;
                vendBank.BankCodeType       = _workerBankAccount.BankCodeType;
                vendBank.BankIBAN           = _workerBankAccount.BankIBAN;
                vendBank.CellularPhone      = _workerBankAccount.CellularPhone;
                vendBank.ContactPerson      = _workerBankAccount.ContactPerson;
                vendBank.Email              = _workerBankAccount.Email;
                vendBank.Location           = _workerBankAccount.Location;
                vendBank.Location           = _workerBankAccount.Location;
                vendBank.Name               = _workerBankAccount.Name;
                vendBank.Phone              = _workerBankAccount.Phone;
                vendBank.PhoneLocal         = _workerBankAccount.PhoneLocal;
                vendBank.RegistrationNum    = _workerBankAccount.RegistrationNum;
                vendBank.SWIFTNo            = _workerBankAccount.SWIFTNo;
                vendBank.TeleFax            = _workerBankAccount.TeleFax;
                vendBank.Telex              = _workerBankAccount.Telex;
                vendBank.URL                = _workerBankAccount.Url;
                vendBank.CurrencyCode       = vendTable.Currency;
                
                if (vendBank.RecId == 0)
                {
                    vendBank.insert();
                }
                else
                {
                    vendBank.update();
                }
    
                if(vendTable.BankAccount != vendBank.AccountID)
                {
                    vendTable.BankAccount = vendBank.AccountID;
    
                    vendTable.Update();
                }
            }
            else
            {
                throw error(strFmt('@XX:WorkerVendorBankAccountError', worker.name()));
            }
        }
    }

  • GirishS Profile Picture
    27,827 Moderator on at

    If you want to restrict the creation of bank account when vendor bank update failed - Then add your logic in the validateWrite method of form DataSource. Add the same logic inside the validateWrite method of worker bank account DataSource.  

    [ExtensionOf(formdatasourcestr(FormName, DataSourceName))]
    final class ClassName_Extension
    {
        public boolean validateWrite()
        {
            boolean ret;
    
            ret  =  next validateWrite();
    
            if (ret)
            {
                        
               if(vendTable)
               {
                //add your logic to update vend table
               }
               else
               {
                    ret  = checkfailed("Error message");
               }
            }
    
            return ret;
        }
    
    }

    Thanks,

    Girish S.

  • D365FO user Profile Picture
    465 on at

    Hi Girish,

    so it's not doable on table level?

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 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans