Skip to main content

Notifications

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

button enabled or disabled in form without refresh

(0) ShareShare
ReportReport
Posted on by

Hi team,

I wrote below code to enable or disable the buton. 

class SalesInvoiceOrgActiveEventHandlers
{
    /// 
    /// to enable or disbale SalesInvoiceOriginal button based on setup in Cust parameter.
    /// 
    /// 
    /// 

    

    [FormDataSourceEventHandler(formDataSourceStr(CustInvoiceJournal, CustInvoiceJour), FormDataSourceEventType::Activated)]
    public static void CustInvoiceJour_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        #Define.SalesInvoiceOriginal('SalesInvoiceOriginal')
        CustInvoiceDuplicateTable_W     custInvoiceDuplicateTable_W;
        CustInvoiceJour                 custInvoiceJour = sender.cursor();
        FormRun                         element         = sender.formRun();
        FormControl                     SalesInvoiceOriginal    = element.design(0).controlName(#SalesInvoiceOriginal);
        FormDataSource                  custInvoiceJour_ds;
        CustParameters                  custParameters = CustParameters::find();

        // This condition is to added to control the SalesInvoiceOriginal button to get disable once the report got executed for 1st time
        // for the current record.
        if (custParameters.RestrictOrgPreview == NoYes::Yes && custInvoiceJour.OrgPreviewPrint == NoYes::Yes)
        {
            SalesInvoiceOriginal.enabled(false);
        }
        else
        {
            SalesInvoiceOriginal.enabled(true);
        }     
    }
    
}

The button is working fine for enabled or disbaled. Once I refreshed the form then only it work properly.

I am looking for enabled or disabled the button without refreshing the form. Kindly let me know what to do?

Please give me more shed on this.

thanks!

  • @rp@n Profile Picture
    @rp@n on at
    RE: button enabled or disabled in form without refresh

    Yes Mohit, I tried it is working fine.

    thanks to all of you again

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: button enabled or disabled in form without refresh

    You don't need to refresh the database, please try adding below code to disable the button. And code on active method will then enable or disable it for other records based on OrgPreviewPrint field value.

    [FormControlEventHandler(formControlStr(CustInvoiceJournal, SalesInvoiceOriginal), FormControlEventType::Clicked)]
    public static void SalesInvoiceOriginal_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        sender.enabled(false);
    }

  • @rp@n Profile Picture
    @rp@n on at
    RE: button enabled or disabled in form without refresh

    Hi Mohit,

    The code to update RestrictOrgPrevie to Yes

    [ExtensionOf(formControlStr(CustInvoiceJournal, SalesInvoiceOriginal))]
    final class CustInvoiceJourSalesInvoiceOriginal_Extension
    {
        CustParameters      custParameters;
            CustInvoiceJour     custInvoiceJour;
            
            custParameters = CustParameters::find();
            
            if (custParameters.RestrictOrgPreview == NoYes::Yes)
                {
                    ttsbegin;
                    select forupdate custInvoiceJour
                        where custInvoiceJour.InvoiceId == custInvoiceJourSelected.InvoiceId;
                    
                    if (custInvoiceJour)
                    {
                        custInvoiceJour.OrgPreviewPrint = NoYes::Yes;
                        custInvoiceJour.doUpdate();
                    }                
                    ttscommit;
                }
    }
    

  • @rp@n Profile Picture
    @rp@n on at
    RE: button enabled or disabled in form without refresh

    yes already I tried. It may many records based on the condition in CustInvoiceJour table and same thing happened. So , I removed that.

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: button enabled or disabled in form without refresh

    Can you add that refresh thing in if and else condition?

  • @rp@n Profile Picture
    @rp@n on at
    RE: button enabled or disabled in form without refresh

    Hi Baharani,

    Recent code

    class SalesInvoiceOrgActiveEventHandlers
    {
        /// 
        /// to enable or disbale SalesInvoiceOriginal button based on setup in Cust parameter.
        /// 
        /// 
        /// 
    
        
        [FormDataSourceEventHandler(formDataSourceStr(CustInvoiceJournal, CustInvoiceJour), FormDataSourceEventType::Activated)]
        public static void CustInvoiceJour_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
            #Define.SalesInvoiceOriginal('SalesInvoiceOriginal')
            CustInvoiceDuplicateTable_W     custInvoiceDuplicateTable_W;
            CustInvoiceJour                 custInvoiceJour = sender.cursor();
            FormRun                         element         = sender.formRun();
            FormControl                     SalesInvoiceOriginal    = element.design(0).controlName(#SalesInvoiceOriginal);
            FormDataSource                  custInvoiceJour_ds = sender;
            CustParameters                  custParameters = CustParameters::find();
    
            // This condition is to added to control the SalesInvoiceOriginal button to get disable once the report got executed for 1st time
            // for the current record.
                        
            if (custParameters.RestrictOrgPreview == NoYes::Yes && custInvoiceJour.OrgPreviewPrint == NoYes::Yes)
            {
                SalesInvoiceOriginal.enabled(false);             
                            
            }
            else
            {
                SalesInvoiceOriginal.enabled(true);            
            } 
            
            /*custInvoiceJour_ds.research();*/
            
        }
        
    
    }

  • @rp@n Profile Picture
    @rp@n on at
    RE: button enabled or disabled in form without refresh

    Hi all,

    I have chacked in CutInvoiceJournal.extension form , SalesInvoiceJournal button property "AutoRefreshData" this is also non editable. it's locked

    pastedimage1682704517516v1.png

    Pls give me more shed on this.

    thanks!

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: button enabled or disabled in form without refresh

    Can you show the present code which you have written till now?

  • @rp@n Profile Picture
    @rp@n on at
    RE: button enabled or disabled in form without refresh

    Hi All

    I tried, with ds.research() after if condition . but the issue is when I am trying open the Invoice Journal form it is gone totally hanged. not opening.

    when I coment my code, then the form get opened.

    pls give me more shed on this.

    thansk!

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: button enabled or disabled in form without refresh

    Understood Girish. Thank you.

    Exactly try using research as I said earlier. That does the same job as the soft refresh.

    So try ds.research();

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,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans