Skip to main content

Notifications

Announcements

No record found.

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

Create validation before click production order post button

(1) ShareShare
ReportReport
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,613 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,445 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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans