Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Suggested answer

get data from edit method in form extension

Posted on by 41
Hi
 
I created an extension to the PriceDiscAdmSearch Form. It's a checkbox. it is an edit method not bound to a datasource or table so it is a form method.
For the PriceDiscAdmSearch class I created an extension as well and added a parmMethod. This is called from the Formextension closeOK - Method (like the standard is doing it)

the standard field are working fine but the value in the class set by is always false even when I set it to true. 
 
Any ideas where this issue comes from and how to solve it?

 
  • Martin Dráb Profile Picture
    Martin Dráb 229,443 Most Valuable Professional on at
    get data from edit method in form extension
    You should learn how to use the debugger. You see that you're unable to solve your problem if you have no idea which part of your code is wrong, there you really need the insight that the debugger can give you.
     
    You may also share your code with us, so we can spot obvious bugs. We can't do anything it at all if you just did something and it didn't work. But this isn't a replacement of debugging; that's a crucial skill that you need to learn ASAP. There in an old joke about it saying: "Only half of programming is coding. The other 90% is debugging."
  • CU31101249-0 Profile Picture
    CU31101249-0 41 on at
    get data from edit method in form extension
    thanks. for the advice. this was the perfect hint

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 229,443 Most Valuable Professional on at
    get data from edit method in form extension
    I don't see your pictures, but all right, I understand that you're saying that the value gets successfully passed to the class and we can completely ignore the form and the edit method; all the discussion about them wasn't relevant to your actual problem.
     
    Regarding the class, you're still making a mistake of not thinking about when and where the value is true or false. I'm assuming that the value is set correctly to the object referenced from the form, but it's not there anymore in run() method and any code called from there. That's because it's a different object and you forgot to add your variable to pack() and unpack() methods. It's a common mistake when using the RunBase framework.
     
    With RunBase, you create an object and set it for execution, which could be later in batch or a different tier in AX (before F&O), therefore the object state is serialized to a container (with pack()), a new object is created (on a batch server or so) and it's populated with the serialized values (with unpack()). Because you didn't add your variable to this logic, the new object can't set the value you wanted and the variable will have the default value (false).
     
    See Extend the RunBase class to learn how to extend pack() and unpack().
  • CU31101249-0 Profile Picture
    CU31101249-0 41 on at
    get data from edit method in form extension
    so ok

    in the closeOk method the value of cemSkipNonEmptyDates is TRUE. it is transfered to the PriceDiscAdmSearch class over the parm method you can see.
    During the execution the formrun class method task is called and there servicemanager.PostFormTask is called (with the true value assigned to cemSkipNonEmptyDates. 


    so the form execution seems to be finished and it goes over to the class executing....the class where we set the true value with the parm method and it's false after fromrun execution finished. 

    The implementation like the existing standard edit method on the form are implemented just that I have to call it in an extension with COC.
    (currency, include generic currency, prices, linediscounts, ......)
  • Martin Dráb Profile Picture
    Martin Dráb 229,443 Most Valuable Professional on at
    get data from edit method in form extension
    No, it's not normal that closeOk() is called many times. If you're talking cemSkipNonemptyDates() method, then it's true it may be called many times, but it's not the code I'm talking about.
     
    If it's really closeOk() that is called many times, please follow my previous advice to find what code is making these calls.
     
    For reference, this is your code and your comment in question:
    public void closeOk()
    {
        priceDiscAdmSearch.parmSkipNonEmptyDates(cemSkipNonEmptyDates); //SEEMS TO RUN MULTIPLE TIMES AND IS FALSE EVEN IF SET TO TRUE ON THE LAST RUNS
    
        next closeOk();
    }
    and I'm asking about the value of cemSkipNonEmptyDates variable.
  • CU31101249-0 Profile Picture
    CU31101249-0 41 on at
    get data from edit method in form extension
    as mentioned in my comments many times the code is called many times (seems to be normal in the extensions) in the first call it is true but turns into false in the other calls of the COC 

    the system forgets about the value during the execution 
  • Martin Dráb Profile Picture
    Martin Dráb 229,443 Most Valuable Professional on at
    get data from edit method in form extension
    You're saying that the value is true, but not value of which variable, where and when. So it says very little.
     
    Please tell us whether cemSkipNonEmptyDates variable is true in closeOK() when you're passing it to parmSkipNonEmptyDates(). It it is, then what you're talking about in the comment at that line (claiming that IS FALSE)?
  • CU31101249-0 Profile Picture
    CU31101249-0 41 on at
    get data from edit method in form extension
    Hi Martin
     
    The value is set to true on the form where the edit method is attached which (didn't make a screenshot).
     
    I debugged the code a hundred times. 
     
    It is true. The code is called so many times (actually I do not know why because this is a bis mysteria to me.) in the first run it is still true and then it changes to false
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 229,443 Most Valuable Professional on at
    get data from edit method in form extension
    When you say "the value", do you mean cemSkipNonEmptyDates variable in PriceDiscAdmSearch form? If so, we can completely ignore PriceDiscAdmSearch class. It's expected that skipNonEmptytoDates is always false if you never set it to true.
     
    In PriceDiscAdmSearch form, was the value ever set to true? Debug cemSkipNonemptyDates() to verify that it's called and it sets cemSkipNonEmptyDates to true. If it does, the value must be changed back to false by some other code.
     
    Also, please tell us more about what you mean by "seems to run multiple times". Are you saying that closeOK() is called multiple times? That sounds strange. Again, the debugger can tell you more about what happened - watch out for the stack trace to understand where the method was called from.
  • Jesús García Profile Picture
    Jesús García 248 on at
    get data from edit method in form extension
    Maybe you have to change the next run() line to earlier position? Before "if"

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,443 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans