web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / formContext.data.save ...
Power Apps
Unanswered

formContext.data.save stuck in error-loop in model driven app with validation

(0) ShareShare
ReportReport
Posted on by

Hi

 

I have a model driven app where I want to check a client ID-number against the records already in the Dataverse table. When a match is found, the save-event has to be cancelled and a warning has to be displayed to the end-user.

 

I'm using the onSave event handler where I call the preventDefault() method, after which I look for existing records (with Xrm.WebApi.retrieveMultipleRecords) with an ID identical to the one provided in the new record.

 

 

function retrieveRecordsWithSameRRNR(rrnr, formContext, id) {
 Xrm.WebApi.retrieveMultipleRecords("vtt_client", "?$select=vtt_clientid,vtt_naam&$filter=vtt_rrnr eq '"+rrnr+"'").then(
 (success) => {
 console.log(success);
 if((success.entities.length > 0 && !id) || (success.entities.length > 1 && id)) {
 //some notification warning the user that a client with the same ID already exists
 } else {
 console.log("rrnr ok");
 formContext.data.save().then(
 (success) => {
 console.log(success);
 },
 (error) => {
 console.log(error);
 }
 )
 };
 }, 
 (error) => {
 //error notification
 }
 )
};

function onSave(executionContext) {
 var formContext = executionContext.getFormContext();
 var rrnr = formContext.getAttribute("vtt_rrnr");
 var rrnrClean = rrnr.getValue().toString().replace(/\D/g, "");
 var id = formContext.data.entity.getId();

 executionContext.getEventArgs().preventDefault();

 retrieveRecordsWithSameRRNR(rrnrClean, formContext, id);
}

 

 

So far so good, but the trouble begins when no match is found and the save event can continue. Here I use the formContext.data.save() method in the callback of the retrieveMultipleRecords method, but when I try to create a new record in the app the data.save() method keeps returning an error.

 

Furthermore the save event keeps on firing indefinitely (as if it notices the error and tries to repeat saving only to reproduce the same error). The error-code is 2200000005 and the translated error message reads something like "the form cannot be saved due to a changed setting". It doesn't specify however what setting seems to be causing the problem (I have activated the asynchrone event handlers in the app-settings, but when I de-activate them, the error remains).

 

Instead of calling the data.save() method in the callback I've also tried using async/await, but the result is the same. I've looked around for solutions to the problem but haven't been able to find an answer. I could retrieve the records onLoad and check onSave whether the ID is in the retrieved records, but this isn't ideal.

 

Hopefully someone has encountered the same error and knows a solution!

 

Thanks in advance!

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @pjbogaert - before I look into this in more depth, what is preventing you from using the out-of-the-box duplicate detection rules in Dataverse?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 549 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 225 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 224

Last 30 days Overall leaderboard