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

Access buttons from formds str

(0) ShareShare
ReportReport
Posted on by 172

Hi,

how can access button properties from form ds str?

I can do it from form str but after some extensions from outside my code is used like 2-3 times on form run and goes so it works really bad.

Actually when I pick more than one row I can invoice a row that alone shouldn't be invoiced.

[ExtensionOf(formstr(SMAServiceOrderTable))]
final class SMAServiceOrderTableSZM_Extension
{
    public void setButtonAccess()
    {
        next setButtonAccess();

        FormDataSource              smaServiceOrderTable_ds = this.datasource();
        smaServiceOrderTable        smaServiceOrderTable = smaServiceOrderTable_ds.cursor();

        SalesLine sline;

        multiselectionhelper        selectionhelper = multiselectionhelper::construct();
        Set                         selectedrecords = new Set(Types::Record);

        selectionhelper.parmDatasource(smaServiceOrderTable_ds);
        smaServiceOrderTable = selectionhelper.getfirst();

        if (smaServiceOrderTable.RecId)
        {
            while (smaServiceOrderTable)
            {
                selectedRecords.add(smaServiceOrderTable);
                info(strFmt('Selected record.. %1',smaServiceOrderTable.serviceorderid));//Display selected record
            
                select firstonly sline where sline.ServiceOrderId == smaServiceOrderTable.serviceorderid
                    && sline.SalesStatus == SalesStatus::Backorder;
                    
                Info(strFmt("%1,%2,%3", sline.ItemId, sline.SalesStatus, sline.ServiceOrderId));
                if(sline)
                {
                    ctrlHeadTransferBUtton.enabled(false);
                }
                smaServiceOrderTable = selectionHelper.getNext();
            }
        }
        
    }

}

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi Radek,

    Can you describe what you want to achieve? What is the customer process and what is the gap in the standard application?

  • Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    Can't you refer to the button by element.ctrlHeadTransferButton?

    You can slightly improve your code by selecting only those fields from SalesLine that you actually use.

  • Blue Wang Profile Picture
    on at
  • RadekM Profile Picture
    172 on at

    The problem is that it is possible to post invoice service orders when multiselected if there is selected a service that can be invoiced.

    For example: I have 3 services one of them can be invoiced other 2 not. But when i select them all together I can invoice them all.

    Did I went wrong here? I just get invalid token error for '('. On formdatasource str

    element.ctrlHeadTransferBUtton.enabled(false);

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi RadekM,

    You can add additional button variable and use it instead of a button from element directly

    FormButtonControl fbc = any2Object(element.ctrlHeadTransferBUtton); //Or it could FormFunctionButtonControl
    fbc.enabled(false);

  • RadekM Profile Picture
    172 on at

    Well it helped me but now the problem is. Everytime the buttons are overwritten. After my method it always run the standard setButtonAccess() method and the result is overwritten by it

  • Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    That's the expected bahavior, if your code runs before setButtonAccess().

    But that's not the case of the code you shared before (where you used CoC and called your logic below 'next'), therefore you must be talking about some other implementation that you didn't share with us.

  • RadekM Profile Picture
    172 on at

    The code above had the issue that it was running multiple times on formrun. 3 times at form start 2 times at changeselection. it wasn't really good

    The code below runs one but it gets overwritten ... I need to archive that it runs once and it runs after the standard method 

    [ExtensionOf(formDataSourceStr(SMAServiceOrderTable, SMAServiceOrderTable))]
    final class SMAServiceOrderTableSZM_Extension
    {
        public int active()
        {
            next active();
            FormDataSource              smaServiceOrderTable_ds = this;
                //sender.dataSource(formDataSourceStr(SMAServiceOrderTable, SMAServiceOrderTable_DS));
            smaServiceOrderTable        smaServiceOrderTable = smaServiceOrderTable_ds.cursor();
    
            SalesLine sline;
            int ret,i;
            container values;
    
            multiselectionhelper        selectionhelper = multiselectionhelper::construct();
            Set                         selectedrecords = new Set(Types::Record);
    
            selectionhelper.parmDatasource(smaServiceOrderTable_ds);
            smaServiceOrderTable = selectionhelper.getfirst();
    
            if (smaServiceOrderTable.RecId)
            {
                while (smaServiceOrderTable)
                {
                    selectedRecords.add(smaServiceOrderTable);
                    info(strFmt('Selected record.. %1',smaServiceOrderTable.serviceorderid));//Display selected record
                    values  = smaServiceOrderTable.serviceorderid;
                    select ServiceOrderId, ItemId, SalesStatus from sline where sline.ServiceOrderId == smaServiceOrderTable.serviceorderid;
                    if(sline.SalesStatus == SalesStatus::Backorder)
                    {
                        FormFunctionButtonControl fbc = any2Object(element.ctrlHeadTransfer);
                        fbc.enabled(false);
                        FormFunctionButtonControl fbc2 = any2Object(element.ctrlHeadTransferButton);
                        fbc2.enabled(false);
                    }
    
                    smaServiceOrderTable = selectionHelper.getNext();
                    
                }
                /*
                for (i = 1; i <= conLen(values); i  )
                {
                    select ServiceOrderId, ItemId, SalesStatus from sline where sline.ServiceOrderId == smaServiceOrderTable.serviceorderid
                        && sline.SalesStatus == SalesStatus::Backorder;
                    */
                
            }
            return ret;
        }
    }

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi RadekM,

    If you check the usage of setButtonAccess method, it's used in header and line active methods. In case if you have an order with lines, first header.active is executed and it probably disables button based on your code. But after header.active method line.active is executed and it just applies standard setButtonAccess rules.

    Perhaps, you will need to implement the same change for line.active method or fallback to CoC for setButtonAccess method.

  • Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    The solution for not running your code multiple times for the same record is caching the value.

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