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

Community site session details

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

To remove record using button

(0) ShareShare
ReportReport
Posted on by 1,836
I have created the button on my form which gets enable disable on certain condition here i want to delete the selected record when the button is clicked the enable/disable condition on button is working fine but how can i remove the selected record can any one guide me on this , my code is below and the button i am using is not command button 
[ExtensionOf(formDataSourceStr(TrvExpenses,TrvExpTrans))]final class DTTrvExpenses_TrvExpTrans_Extension{    [Control(/Button/)]    class DeleteExpenceLines    {        /// <summary>        /// Remove the selected expenses from the expense report        /// </summary>        public void clicked()        {            // Invoke method to process expense line deletion.            // This method should be invoked for deletion from both details view and grid view.            // There is no special processing for deletion from grid view.            this.MyMethodToDeleteLines();            super();        }    }}
 
I have the same question (0)
  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    To remove record using button
    Hi Dinesh,
     
    You need to write code on the clicked method of the new button control.
    If you want to mark the selected lines from the grid on click of button - You need to use multi selection helper class.
    Refer to the below blog.
     
    Thanks,
    Girish S.
     
  • Suggested answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    To remove record using button
    Hi Dinesh, You have written button clicked method control in FormDataSource extension class. Instead either create event handler class and use onClicked event of button or create an extension class of form control.
     
     
    As mentioned below, you can use multi select helper class to find selected records and delete it.
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    To remove record using button
    hi 
     
    Girish s ,
    Mohit Rampal,
     
    Thanks For reply ,
     
     if i create the event handler class , or  extension class of form control where can i call and write my logic in dodelete() method as i want to delete the selected record on form, as the do delete is the table method can u please guide me on this.
     
    thanks regards 
     
    dinesh
     
  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    To remove record using button
    Refer to the below code.
     

    [FormControlEventHandler(formControlStr(FormName, ButtonName), FormControlEventType::Clicked)]
    public static void ButtonName_OnClicked(FormControl sender, FormControlEventArgs e)
    {
       FormButtonControl callerButton = sender as FormButtonControl;
       FormRun form = callerButton.formRun();
       FormDataSource dataSourceName_ds= form.dataSource(formDataSourceStr(FormName, DataSourceName)) as FormDataSource; // datasource name where the records to be deleted.

     //Multiselect helper class

       TableName tableName;//records to delete from

        MultiSelectiper helper = MultiSelectionHelonHelper::construct();
      helper.parmDatasource(dataSourceName_ds);
      tableName= helper.getFirst();
       
      while (
    tableName.RecId != 0)
        {
            tableName.doDelete();

            custPaymModeTablelocal = helper.getNext();
        }

    }

    Thanks,

    Girish S.

  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    To remove record using button
    Replace custPaymModeTablelocal  buffer with tableName buffer.
     while (tableName.RecId != 0)
        {
            tableName.doDelete();

            tableName= helper.getNext();
        }
  • Dineshkarlekar Profile Picture
    1,836 on at
    To remove record using button
    public class TrvExpTrans extends common
    {
     public void doDelete()
        {
            if(!this.canExpenseLineBeDeletedWithApprovalStatus())
            {
                return;
            }
    
            super();
        }
    
        /// <summary>
        /// List of approval Status for which expense line can be deleted
        /// </summary>
        /// <returns> 
        ///     true if we can delete , false if not allowed
        /// </returns>
        private boolean canExpenseLineBeDeletedWithApprovalStatus()
        {
            if( this.ApprovalStatus == TrvAppStatus::None || 
                this.ApprovalStatus == TrvAppStatus::Matched || 
                this.ApprovalStatus == TrvAppStatus::Create )
                {
                    return true;
                }
    
            return false;
        }
    
    }
    the table do delete is having code like this i want to add my condition  
    this.ApprovalStatus == TrvAppStatus::Pending  how can i pass my condition in do delete method ,
     
      /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormControlEventHandler(formControlStr(TrvExpenses, DeleteExpenceLines), FormControlEventType::Clicked)]
        public static void DeleteExpenceLines_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            FormButtonControl callerButton  = sender as FormButtonControl;
            FormRun                  form   = callerButton.formRun();
            FormDataSource   trvExpTrans_ds = form.dataSource(formDataSourceStr(TrvExpenses,TrvExpTrans)) as FormDataSource; // datasource name where the records to be deleted.
    
            //Multiselect helper class
    
            TrvExpTrans          _trvExpTrans ;//records to delete from
    
            MultiSelectionHelper  helper =  MultiSelectionHelper::construct();
            helper.parmDatasource( trvExpTrans_ds);
            _trvExpTrans  = helper.getFirst();
       
            while ( _trvExpTrans.RecId != 0)
            {
                _trvExpTrans.doDelete();
                _trvExpTrans = helper.getNext();
            }
    
        }
        
    }
    thanks,
     
    regards,
     
    Dinesh
  • Dineshkarlekar Profile Picture
    1,836 on at
    To remove record using button
     i  have return the code on form datasource so the click button can call this code for dodelete 
    plz suggest do i have to make any changes in this.
    [ExtensionOf(formDataSourceStr(TrvExpenses,TrvExpTrans))]
    final class DTTrvExpenses_TrvExpTrans_Extension
    { 
      public void doDelete()
        {
            if(!this.canExpenseLineBeDeletedWithApprovalStatus())
            {
                return;
            }
    
        }
    
        /// <summary>
        /// List of approval Status for which expense line can be deleted
        /// </summary>
        /// <returns>
        ///     true if we can delete , false if not allowed
        /// </returns>
       Public boolean canExpenseLineBeDeletedWithApprovalStatus()
        {
            TrvExpTable                     trvExpTable;
    
            if( trvExpTable.ApprovalStatus == TrvAppStatus::Pending)
            {
                return true;
            }
    
            return false;
        }
    
       
    }
    thanks, 
     
    Regards, 
     
    Dinesh
  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    To remove record using button
    Why do you need two methods. You can use single method to achieve this. Also you need to get the current cursor and then check for the condition. Refer to the below code.
    [ExtensionOf(formDataSourceStr(TrvExpenses,TrvExpTrans))]
    final class DTTrvExpenses_TrvExpTrans_Extension
    { 
        /// <summary>
        /// List of approval Status for which expense line can be deleted
        /// </summary>
        /// <returns>
        ///     true if we can delete , false if not allowed
        /// </returns>
       Public boolean doDelete()
        {
            TrvExpTable                     trvExpTable;
            trvExpTable = this.cursor();
            if(trvExpTable.ApprovalStatus == TrvAppStatus::Pending)
            {
                return true;
            }
    
            return false;
        }
    
       
    }
  • Dineshkarlekar Profile Picture
    1,836 on at
    To remove record using button
     hi
     
    Girish s,
     
    I have made the changes in do delete method, but the debugger is not going into , but the debugger is not getting in this method and the record is not getting deleted.
    [ExtensionOf(formDataSourceStr(TrvExpenses,TrvExpTrans))]
    final class DTTrvExpenses_TrvExpTrans_Extension
    {  
     /// <summary>
        /// List of approval Status for which expense line can be deleted
        /// </summary>
        /// <returns>
        ///     true if we can delete , false if not allowed
        /// </returns>
        Public boolean doDelete()
        {
            TrvExpTable     trvExpTable;
            trvExpTable = this.cursor();
            if(trvExpTable.ApprovalStatus == TrvAppStatus::Pending)
            {
                return true;
            }
    
            return false;
        }
    }
    instead it hitting this dodelete method
    public class TrvExpTrans extends common
    {
     public void doDelete()
        {
            if(!this.canExpenseLineBeDeletedWithApprovalStatus())
            {
                return;
            }
    
            super();
        }
    
        /// <summary>
        /// List of approval Status for which expense line can be deleted
        /// </summary>
        /// <returns> 
        ///     true if we can delete , false if not allowed
        /// </returns>
        private boolean canExpenseLineBeDeletedWithApprovalStatus()
        {
            if( this.ApprovalStatus == TrvAppStatus::None || 
                this.ApprovalStatus == TrvAppStatus::Matched || 
                this.ApprovalStatus == TrvAppStatus::Create )
                {
                    return true;
                }
    
            return false;
        }
    
    }
     
  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    To remove record using button
    I am confused. To make it simple it's not necessary to create new method and add a validation there - You can add the validation inside the clicked method itself. - Inside multi selection helper class.
    If you still need it, please share the code on the clicked method.
     
    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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,177

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 593 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans