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

Creating a validation field in BOM onclick with form extension

(0) ShareShare
ReportReport
Posted on by 172

Hello. As it's said im a beginner in MS Dynamics and programming. Im trying to do multiple task but i lack on skills so here I have questions.

1. As for working with extensions, I need to create new functionalities. Do I need only to create a new class ? How should I run it for the extended form I have in my solution ?

2. Is there a simple way to compare enum values in select ? Actually I need to select all enum values except for one and adding just more values makes it look bad.

3. How to simply disable allowedit value for a field in extension from a new class ?

Will add more in time..

I have the same question (0)
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    Please use descriptive titles for your threads. Here you failed to do that because you mix several different topics in a single thread. Not only that it's not clear what the thread is about (from its title and tags), but it makes difficult to track with answer belongs to which topic and which questions are answer. You can mark a thread as answered, but you can't mark 1/3 of a thread as answered. Therefore you should create a separate thread for each topic.

    Anyway, let me quickly address your questions:

    1. No, classes are not the only elements that you may want to create or modify. Think about tables, table extensions, forms, data entities, data types, security elements and so. Everything you can find in AOT is useful in some situations.
    2. Use operators ==, != or in(). For example: where meetable.MyField != MyEnum::MyEnumElement.
    3. Please give us more details. For instance, can't you simply do it in a form extension instead of a class. Maybe you some conditions, but you forgot to mention it...
  • RadekM Profile Picture
    172 on at

    1. Indeed I took into my solution just a table and form because I need to create a function for a field there.

    2.  while select ProdId, ProdStatus, InventRefType, InventRefID from ProdTable where  InventRefType != InventRefType::None     -

     it gives me just error ' qualifier inventreftype is not valid in this context

    3. My only condition is to block edit field if a certain statement is not true.

  • Suggested answer
    Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    2. You forgot to specify the table:

    while select ProdId, ProdStatus, InventRefType, InventRefID
        from prodTable
        where prodTable.InventRefType != InventRefType::None

    3. The next thing you must decide is when you want to check the condition (e.g. when opening the form, when switching to another record or so). It depends on when the check may start giving different results, but because you're the only one who knows that, it's up to you...

  • RadekM Profile Picture
    172 on at

    1. So when I want to run it when the form starts I neeed to write my class in init method or maybe run ? How should I connect it with my extended form ? I need to work only on one table element. That element need to change properites on a certain condition.

    2. It was so simple... did not specified the table...

    3. I want to run as soon as my form starts.

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

    1. What are you talking about here? Are you know reusing point 1 for the same topic as point 3, or are you talking about something else? This thread is chaotic.

    3. init() method is the right place for form initialization logic. If you're extending an existing form, you can either use CoC or event handlers.

  • RadekM Profile Picture
    172 on at

    All these questions are for one my task. Down I put my whole code.

    I'm trying to check if ProdStatus is Finished and enable or disable checkbox EndJob so noone can end the BOM if any item is not marked af finished. I'm working on a extension of form and table.

    public class ProdParmReportFinishedVerify extends FormRun
    {
       ProdParmReportFinished ProdParmReportFinished;
       ProdTable ProdTable;
     
    
       public void init()
       {
    
            {
                while select ProdId, ProdStatus, InventRefType, InventRefID from ProdTable where  ProdTable.InventRefType != InventRefType::None
             
                if(ProdStatus::ReportedFinished)
            {
                
                ProdParmReportFinished.EndJob = NoYes::Yes;
    
          [FormControlEventHandler(formControlStr(ProdParmReportFinished, ProdParmReportFinished_EndJob), FormControlEventType::Validating)]
         // public static void ProdParmReportFinished_EndJob_OnValidating(FormControl sender, FormControlEventArgs e)
         public static void ProdParmReportFinished_EndJob_OnValidating(XppPrePostArgs args)
          {
              FormRun sender = Args.getThis();
              sender.control(sender.controlId(formControlStr(ProdParmReportFinished, ProdParmReportFinished.EndJob))).allowEdit(false);
          }
    
              // info(' Success');
            }
                 else
                {
                   ProdParmReportFinished.EndJob = NoYes::No;
    
    
                 [FormControlEventHandler(formControlStr(ProdParmReportFinished, ProdParmReportFinished_EndJob), FormControlEventType::Validating)]
                 public static void ProdParmReportFinished_EndJob_OnValidating(FormControl sender, FormControlEventArgs e)
                 {
                     FormRun sender = Args.getThis();
                     sender.control(sender.controlId(formControlStr(ProdParmReportFinished, ProdParmReportFinished.EndJob))).allowEdit(false);
                 }
    
                   warning(' Failed verification');
                    break;
                }
            }
    
      
           }
    
    }

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

    I couldn't know that, because you never say that. Now when finally know what this thread is about, can you please give it a descriptive name?

    A few comments about your code:

    • It will never compile, because you have event handlers embedded in init() method.
    • Even if you put event handler methods at the righty level, they won't compile, because you're trying to using a non-static variable in static methods.
    • I see you're writing a form and not an extension. Then you don't need even handler methods at all; simply override the methods you need.
    • form controls by name; you don't need sender.control().
    • I don't think that the form control is called ProdParmReportFinished.EndJob - it would be another compilation error.
    • Never use XppPrePostArgs - that's used for Pre-/Post-method event handlers, but now you can do it in a much easier and safer way with chain of command (CoC).
    • if(ProdStatus::ReportedFinished) does nothing - it seems that you wanted to compare this value with a field, but you forgot.
    • You assign values to prodParmReportFinished, but you never use them for anything. You said you wanted to make a checkbox non-editable, so why are you changing the value of the field? And because ProdParmReportFinished is a new variable created by yourself, it has nothing to do with anything shown in the form.
    • You said you wanted to use a condition, but you always set AllowEdit to false. If you want a condition, you forgot to add it. If you want AllowEdit = No, you don't need any code at all, simply set the property value.

    Please pay attention to what the compilers tells you. And realize that you can look at the implementation of other forms in the application and learn from it.

    If the checkbox is bound to a datasource field, the right solution is this:

    boolean isEditable = ...
    prodParmReportFinished_ds.object(fieldNum(ProdParmReportFinished, EndJob)).allowEdit(isEditable);

  • RadekM Profile Picture
    172 on at

    I do not write a form. I created a new class and this is all the code from it. In my solution is just form extension and table axtension + this new class.

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

    You've just showed us this code:

    public class ProdParmReportFinishedVerify extends FormRun

    That's a form declaration. Maybe you copied it from a form not realizing what you're doing.

    This is how you would create a class to extend business logic of a form:

    [ExtensionOf(formStr(ProdParmReportFinished))]
    final class MyProdParmReportFinished_Extension

  • RadekM Profile Picture
    172 on at

    This code gives me error prodParmReportFinished_ds not found in this scope

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 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans