Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / controle button depend...
Finance forum
Answered

controle button depending from where the form was opened

Posted on by 52
hello everyone i'm trying to controle a button that i added in SalesEditLine. 
if i open SalesEditLine from the pro forma invoice button in sales orders, i want it to be disabled.
if i opened it from the Sales Update button in SalesPostingHistory i want it to be disabled.
to do so i tried to use args.caller() but the caller is SalesFormLetter in both cases so it didn't work.
i tried to pass a parameter in the clicked method of the button so i can use it in the init method of SalesEditLine form this is the code.
[Control(/Button/)]    class ButtonUpdate    {        void clicked()        {            Args    args;            super();            str test = 'test';            args = new Args();            args.record(salesParmTable);            args.parmEnum(enum2int(DocumentStatus::Invoice));                        args.name(formstr(SalesEditLines));                        args.parm(test);            SalesFormLetter::main(args);                        salesParmTable_ds.active();        }    }
but i get this error.
any solution to this error or any other solution for the problem.
thank you for help.
  • Community member Profile Picture
    Community member 52 on at
    controle button depending from where the form was opened
    it worked, thank you Marin for your help.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,126 Most Valuable Professional on at
    controle button depending from where the form was opened
    OK, let me show you how to get the answer.
     
    When you look at what ButtonUpdate in SalesPostingHistory does, you'll see this code:
    args = new Args();
    args.record(salesParmTable);
    args.parmEnum(enum2int(documentStatus));
    
    SalesFormLetter::main(args);
    If you want to know what happens inside main(), simply go to the definition. You'll find that args.record() is set to a local variable called record, which is then passed to SalesFormLetter::constructAndInitialize(). That calls initializeFromCallerRecord(), where you're interested in the section initializing the object from SalesParmTable. Remember, that's the table I pointed out to in my previous reply. There you'll see this call: this.parmCreateFromHistory(true).
     
    That's you answer. You can use parmCreateFromHistory() method of SalesFormLetter class to determine whether the call was made from posting history.
  • Community member Profile Picture
    Community member 52 on at
    controle button depending from where the form was opened
    thank you Martin for your answer.
    how can i use SalesFormLetter object to determine which form is the caller or which button is the caller?
  • Martin Dráb Profile Picture
    Martin Dráb 228,126 Most Valuable Professional on at
    controle button depending from where the form was opened
    Isn't the difference in that SalesPostingHistory from creates a SalesFormLetter object for an existing SalesParmTable record?
     
    Hard-coding DocumentStatus::Invoice in SalesPostingHistory is a bad idea, because this form is used for other posting types as well.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,126 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans