Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Are we able to skip va...
Finance forum
Suggested answer

Are we able to skip validateWrite() in standard table entity?

Posted on by 55

Hi, 

In my case, the idea is I want to disable or skip the standard validation in SalesOrderLineV2Entity.validateWrite(). The purpose of I am doing so is because inside the validateWrite() got validation or condition where not allow us (prompt and error message) to update the sales order with retail channel. It works fine on sales order without retail channel. Then, I have done some research and I found similar scenario where the developers create an extension as below to skip that validate method : 

[ExtensionOf(formdatasourcestr(DataEntityToExtend))]

final class DataEntityToExtend_Extension

{

public boolean validateWrite()

{

boolean ret;

//ret = next validateWrite();

return ret;

}

As we can see they commented the next validateWrite(); But the thing is all the scenarios that I found was in 'formdatasourcestr' not in 'tablestr'. The issue that I am facing currently, they triggered the validateWrite() from table entity. I was wondering, is it possible if this solution was only applicable to formdatasourcestr only and not applicable to tablestr(SalesOrderLineV2Entity) ? Can anyone help me. Thank you in advance.

  • nadiah sukerman Profile Picture
    nadiah sukerman 55 on at
    RE: Are we able to skip validateWrite() in standard table entity?

    Yes, the entity itself. but actually I already done the copy of the entity all methods there and change the condition of validations. Unfortunately, there are two method are inaccessible

    community.dynamics.com/.../1059650

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Are we able to skip validateWrite() in standard table entity?

    Ah, ok so it's in the entity itself. And it doesn't support ANY changes for retail-based order lines.

    If you really need to do such updates, I recommend to copy the standard entity and remove this validation. You were worried that it maybe wouldn't work as the standard one, but actually your requirement is that it shouldn't work as the standard one :)

    But with this approach you would at least still have all the other validations. If you would use Chain of Command and change the return value of validateWrite() of the standard entity, you would skip all validations which is much worse.

  • nadiah sukerman Profile Picture
    nadiah sukerman 55 on at
    RE: Are we able to skip validateWrite() in standard table entity?

    Thank you Nikolaos, by the way I'm so sorry I was accidentally click actions reported as abusive while I want to click like button.

    Actually this is the condition where I want to edit. inside SalesOrderLineV2Entity, it triggered that checkfailed when we tried to update the serial no field and that serial no is same as the serial no I created. And this issue only happened only on sales order with retail channel. 

    public boolean validateWrite()

    {

       SalesTable salesTable = SalesTable::find(this.SalesOrderNumber);

           if (this.RecId)

           {

               if (RetailParameters::isRetailEnabledAndInUse()

                   && RetailSalesTable::find(this.SalesOrderNumber).RetailChannel)

               {

                   return checkFailed("@SCM:SalesOrderLineEntityDoesNotSupportUpdatesOfRetailOrders");

               }

           }

    }

    1325.Capture.PNG

    Yeah, I'm aware this approaches will might encounter an issue since it is a standard validation. Do you have any idea on how i'm going to deal with it based on your knowledge & experiences? since we got a request from client side to allow that update or else replicate that entity which I think it's not an appropriate way to replicate it since it might wouldn't work as the standard one. Thank you in advance.

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Are we able to skip validateWrite() in standard table entity?

    When the next() is called, the standard validations are triggered. And it will display messages if the standard validations failed. But if you change the return value to true after that, the validation is still succesful and the record is saved.

    But what is the exact validation that is causing you trouble? Perhaps there's some other way to resolve your requirement.

    On the other hand, the standard validations are there for a reason so if you bypass them, you might encounter issues. I don't know retail functionality very well, but wouldn't your scenario mean that you would have different serial number in the store and in the order line? Perhaps this causes issues further down the process.

  • nadiah sukerman Profile Picture
    nadiah sukerman 55 on at
    RE: Are we able to skip validateWrite() in standard table entity?

    Thanks for all the answers. But I thought when the "next" return true value and prompt the error message, the process will stop and it wont proceed to the extension of validateWrite()? the error message appeared because the standard process doesn't allow us to do an update for serial number field where the sales order got retail channel id. but my client requested to allow it. Is it possible?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Are we able to skip validateWrite() in standard table entity?

    You must always call next. But as Sergey mentioned, you can ignore what the "next" returns and return true instead. However if you bypass the standard validations you risk having corrupt data in your system, which might not be so easy to fix in Prod.

    Remember that if you ignore the result of validateWrite, you will ignore ALL standard validations and now you let any user who has access to this entity (for example via Excel add-in) to create potentially bad data.

    Also, a data entity is not a form data source, so you should not use "formDataSourceStr" in your extension class. Use "dataEntityViewStr(EntityName)".

  • Suggested answer
    Sergei Minozhenko Profile Picture
    Sergei Minozhenko 23,083 on at
    RE: Are we able to skip validateWrite() in standard table entity?

    Hi Nadiah,

    You can't skip next statement (I'm not sure if the mentioned code is working), but you can try to return true in extension method instead of result from next statement to bypass validation.

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