Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

button enabled or disabled in form without refresh

Like (0) ShareShare
ReportReport
Posted on 28 Apr 2023 13:41:43 by 4

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
    4 on 29 Apr 2023 at 02:29:24
    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
    12,554 Moderator on 29 Apr 2023 at 02:23:12
    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
    4 on 29 Apr 2023 at 01:37:21
    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
    4 on 28 Apr 2023 at 18:10:00
    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
    3,618 Moderator on 28 Apr 2023 at 18:06:46
    RE: button enabled or disabled in form without refresh

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

  • @rp@n Profile Picture
    4 on 28 Apr 2023 at 17:59:39
    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
    4 on 28 Apr 2023 at 17:56:12
    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
    3,618 Moderator on 28 Apr 2023 at 17:56:06
    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
    4 on 28 Apr 2023 at 17:32:21
    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
    3,618 Moderator on 28 Apr 2023 at 16:17:13
    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading complete