web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Create validation before click production order post button

(1) ShareShare
ReportReport
Posted on by 73
Hello all,
I want to create a validation when the post button is clicked. The validation is quite simple where I need to make sure all the data to be posted has a costcenter that is not 000.
 
 
so I made a custom coding like the following and it didn't give any effect, any advise?
    /// <summary>
    ///
    /// </summary>
    /// <param name=/sender/></param>
    /// <param name=/e/></param>
    [FormControlEventHandler(formControlStr(ProdJournalTransBOM, PostJournal), FormControlEventType::Clicked)]
    public static void PostJournal_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        ProdJournalBOM  prodJournalBOM;
        FormControl formButtonControl = any2Object(sender) as FormControl;
        FormDataSource formDatasource = formButtonControl.formRun().dataSource(tableStr(ProdJournalTable));
        ProdJournalTable prodJournalTable = formDatasource.cursor();
        while select prodJournalBOM
        while select prodJournalBOM
            where prodJournalBOM.JournalId == prodJournalTable.JournalId
            && ProdJournalType::Picklist == prodJournalTable.JournalType
        {
            DimensionAttributeValueSetItemView  dimensionAttributeValueSetItemView;
            DimensionAttribute                  dimensionAttribute;
            select dimensionAttributeValueSetItemView
                join dimensionAttribute
                where dimensionAttributeValueSetItemView.DimensionAttribute == dimensionAttribute.RecId
                && dimensionAttribute.Name == 'CostCenter'
                && dimensionAttributeValueSetItemView.DimensionAttributeValueSet == prodJournalBOM.DefaultDimension;
            if(dimensionAttributeValueSetItemView.DisplayValue == '000')
            {
                Error('CostCenter 000 dont alowed');
                throw Exception::Error;
            }
        }
    }
 
thank u
 
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    238,270 Most Valuable Professional on at
    It's possible - I'm pretty sure that are many validations in the standard code.
     
    But your code is at a wrong and it can't do the job. It runs after posting and it ignores the standard logic.
     
    The button is linked to ProdJournalPost menu item, which calls ProdJournalCheckPost class. There you can overide checkJournal(), for instance, to implement the validation. Not only it's the most logical place, but it'll support scenarios you forgot about, such as checking the journal without posting.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    As Martin suggested you code doesn't work because this runs at super of clicked method.
     
    You need to either write this at before next in COC or you can check in standard, ProdJournalCheckPost class we have got lot of boolean methods like prerun(), checkjournal(), checktrans() etc which can be used for throwing the validation.

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

News and Announcements

Season of Giving Solutions is Here!

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
Abhilash Warrier Profile Picture

Abhilash Warrier 836 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 349 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans