Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Commerce forum / Create new method rule...
Commerce forum
Unanswered

Create new method rule validation on Commerce Parameter > Transaction Validation

Posted on by Microsoft Employee

Dear All,

I have a requirement to create a new rule validation after we run P-001 job on D365FO. This rule is check Batch Id and Serial Id for sepecific Item. So how can I create new method on RetailTransactionValidationLine class and load it into the Rules Grids as image below. Please help me if you guys have any ideas or suggestion. Thanks a lots

Path:  Retail & Commerce > Head quarter setup > parameters > Commerce Parameters > Transaction Validation 

4747.2021_2D00_05_2D00_27_5F00_10_2D00_19_2D00_12.png

Phuoc Dinh

  • Juliet Zhu Profile Picture
    Juliet Zhu on at
    RE: Create new method rule validation on Commerce Parameter > Transaction Validation

    Hi Phuoc,

    Could you open a support ticket with Microsoft to get someone checking your environment directly?

    Thanks,

    Juliet

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create new method rule validation on Commerce Parameter > Transaction Validation

    Dear Juliet Zhu,

    Thank so much for your guidance very clealy. I tried to follow with all your steps but after try to build project and hole model also my new rule still not show up in Rules Grid. Please help me if you have any idea

    Best regards

    Phuoc Dinh

  • Juliet Zhu Profile Picture
    Juliet Zhu on at
    RE: Create new method rule validation on Commerce Parameter > Transaction Validation

    Hello Phuoc Dinh,

    Thank you for using Microsoft Dynamics Communities.

    To create a custom validation rule, you need to:

    • Add new member to the RetailTransactionValidationType extensible enum
    • Create a class that extends RetailTransactionValidationBase
    • For header validations, you need to create a method that resembles the one below:

    [
    RetailTransactionValidation(RetailTransactionValidationRuleType::TransactionLevel, "@Retail:ConsistencyCheckerCustomerAccountDescription"),
    RetailTransactionValidationApplicableToAllTypes
    ]
    public boolean validateCustAccount() {}

    • For line validations, you need to create a method that resembles the one below:

    [
    RetailTransactionValidation(RetailTransactionValidationRuleType::LineLevel, "Validates if the serial number contains unprintable characters"),
    RetailTransactionValidationApplicableToAllTypes
    ]
    internal void validateSerialItemWithUnprintableChars(ItemInfo _itemInfo) {}


    Whenever you detect a problem, you should use either:

    this.insertValidationErrorForTransaction(RetailTransactionValidationType::CUSTOM_ENUM, errorMessage)
    for header level failures.

    this.insertValidationErrorForTransactionWithLineReference(RetailTransactionValidationType:: CUSTOM_ENUM, errorMessage, _itemInfo.LineNumber)
    for line level failures.


    By doing this, the validation failure will be caught by the framework and we will automatically mark the transaction as failed.

    You can use RetailTransactionValidationHeader & RetailTransactionValidationLine as examples.

    Note: once you do this, the new rule should automagically show up in Commerce Parameters > Transaction Validation.

    Hope it helps.

    Juliet Zhu

    If my information answers your question please click 'Yes' against "Did this answer your question?" to help other community members. 

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans