Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Create validation before click production order post button

Posted on by 69
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
 
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    Create validation before click production order post button
    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.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,056 Most Valuable Professional on at
    Create validation before click post button
    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,228 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans