
Announcements
Hello everyone,
I don't know whether this is possible or not, but in Model-driven, can we validate data after it is being saved ? So lets say I save a record (new record), I need the form to be validated again, before user accidentally close the form (without save again)
I found this function, but to be honest I don't have any background of CRM nor JavaScript, as I come from D365 Finance & Operation, so I don't how to use it. It is called PostSave ->
Can someone give me a guidance over here ?
Thanks in advance.
That is precisely the correct event to attach to. The addOnPostSave function allows you to tell Dataverse "hey, after a save is completed, I want you to do this thing over here." so the way you use it is you build a function that does the validation you want, then during the onLoad event you call this addOnPostSave function and pass it the function you want it to run in the post save event. Let me give you an example:
function onLoad(executionContext) {
var formContext = executionContext.getFormContext();
formContext.data.entity.addOnPostSave(doMyValidation);
}
function doMyValidation(executionContext)
{
if (1 != 2) {
console.log("Of course 1 is not equal to 2!")
}
}So first, you register the function onLoad on the form during the onLoad event. Easy. Then when the form opens, it runs this code. The code tells the form that whenever the postSave event happens, it should call the function "doMyValidation". Then, when the user hits save during the post event the form calls doMyValidation.
Now, all that is easy enough, but you will have to then write your validation logic, and there's not much I can do to help you with that. What I can tell you is that if you've gotten this far you're really close and you just need to trust that the documentation page where you found addOnPostSave is the right place to look for everything else you need for validation like checking the value of fields and updating them if necessary.