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 76

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..

  • RadekM Profile Picture
    RadekM 76 on at
    RE: Creating a validation field in BOM onclick with form extension

    It might be suprising but I already got to this point ! Ha ha Even further I'm like 99% sure I did it on the wrong form extension. Well actually the whole grid with data is on a other form ProdTableListPage so it might be natural to check it all there. And after that I should call another extensions class for ProdParmForm to disable the Ok button and leave a label for user info. Im thinking if I should use event handlers on dbsource here. OnSelectionChange event with selectionchange() method ? But still I dont know how to refer to the current recid.

    [ExtensionOf(formdatasourcestr(ProdParmReportFinished, ProdParmReportFinished))]
    final class ProdParmReportFinishedActiveWG_Extension
    {
            public void selectionChanged()
            
        {
            
            next selectionChanged();
            {
            // Form handler event onselection change
            }
            
        }
        
    }

  • Martin Dráb Profile Picture
    Martin Dráb 231,309 Most Valuable Professional on at
    RE: Creating a validation field in BOM onclick with form extension

    Think about your code. What was the purpose of running it when switching to a different record? To take some data from the active record and do something with it, right? And do you do that? No! You completely ignore all data in the form - the query will return the same thing every time, because it doesn't depend on any outside data (except of what's in ProdTable, of course).

  • RadekM Profile Picture
    RadekM 76 on at
    RE: Creating a validation field in BOM onclick with form extension

    Well I just have no more idea for this task. 
    Tried to code this with CoC Active() but i get the same problem as with init(). My only option is the statement is completly wrong. Or I need to use it on another form extension ? All rows are showed on ProdListPane but it extends to ProdParmReportFinished. 

    [ExtensionOf(formdatasourcestr(ProdParmReportFinished, ProdParmReportFinished))]
    final class ProdParmReportFinishedActiveWG_Extension
    {
            public int active()
            
        {
            
            next active();
            int ret;
            ProdTable ProdTable;
    
            select RecId from prodTable
                where prodTable.InventRefType != InventRefType::None
                && prodTable.InventRefId == prodTable.ProdId
                  && prodTable.ProdStatus != ProdStatus::ReportedFinished;
    
          //  warning ("@SRM:SRM00049");
            info(strfmt("%1", (prodTable.RecId != 0)));
           // Ok.enabled(false);
    
        return ret;
    
        }
    
    }

  • RadekM Profile Picture
    RadekM 76 on at
    RE: Creating a validation field in BOM onclick with form extension

    Still didn't got any further. Whatever I put into this active method gives nothing. It don't even throw any info.

    But i changed a bit my concept. Insted of working on this endjob field I just disabled the submit button.

  • RadekM Profile Picture
    RadekM 76 on at
    RE: Creating a validation field in BOM onclick with form extension

    Could you show me a use example of this active method ?

      public int active()
        {
            ProdTable prodTable;
            int ret;
    
              if(ProdTable.InventRefId !=ProdTable.ProdId)
            {
                Info("ok");
            }
            return ret;
        }

  • RadekM Profile Picture
    RadekM 76 on at
    RE: Creating a validation field in BOM onclick with form extension

    There is active() method on my datasource and yes i was wrong here.

    Thinking about it first I need to check if current active row with InventRefId is different from ProdID. I don't need to verify items alone. I need to check all rows where InventRefID = ProdID. So if current REFID = PRODID verify all REFID that are equal to current PRODID (because every next refif has different prodid).

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,309 Most Valuable Professional on at
    RE: Creating a validation field in BOM onclick with form extension

    Do you remember when I told you that where you should put your code depends on when you want to evaluate the condition?

    You said you wanted it just once, when opening the form, so it's exactly what you have at the moment.

    It seems that you've just found a bug in your specification and you now must rework your implementation as well. To evaluate the condition when switching from one record to another, use active() method on the datasource.

    You set AllowEdit property of the whole column; you can't set it on individual rows. That's why you must check the condition and set the property when switching records.

  • Martin Dráb Profile Picture
    Martin Dráb 231,309 Most Valuable Professional on at
    RE: Creating a validation field in BOM onclick with form extension

    Please read the previous discussion, I already explained there why the assignment won't work. And I said that if you didn't believe me, you would see it when you'd be able to run your code. Now it's the time. :-)

  • RadekM Profile Picture
    RadekM 76 on at
    RE: Creating a validation field in BOM onclick with form extension

    Well actually this code blocked access to all items. Even when I tried to modify the statemend it just ignored it and rushed the verification.

    But I want to verify only this rows that PRODID != InventRefID and Prodstatus != None. 

    [ExtensionOf(formStr(ProdParmReportFinished))]
    final class ProdParmReportFinishedWG_Extension
    {
        public void init()
        {
            
            next init();
    
            ProdTable prodTable;
    
            if(ProdTable.InventRefType != InventRefType::None || ProdTable.InventRefId !=ProdTable.ProdId)
            {
                Info("ok");
                
            }
            else if(ProdTable.InventRefType == InventRefType::None)
            {
              select firstOnly RecId from prodTable
                where prodTable.InventRefType != InventRefType::None
                   && prodTable.InventRefId == prodTable.ProdId
                   && prodTable.ProdStatus != ProdStatus::ReportedFinished;
    
      
            warning ("@SRM:SRM00049");
    
           // ProdParmReportFinished.EndJob = NoYes::No;
           // ProdParmReportFinished.EndJob = false;
           // ProdParmReportFinished_EndJob.value(false);
    
            prodParmReportFinished_ds.object(fieldNum(ProdParmReportFinished, EndJob)).allowEdit(prodTable.RecId != 0);
        }
        }
    
    }

  • RadekM Profile Picture
    RadekM 76 on at
    RE: Creating a validation field in BOM onclick with form extension

    Could you tell me why this code don't change my checkbox value ?

    No reaction      // ProdParmReportFinished.EndJob = NoYes::No;

    No reaction      // ProdParmReportFinished.EndJob = false;

    FormCheckBoxControl not valid in this context     // FormCheckBoxControl.value(false);

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans