Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

preventDefault() throws error only on Mark Complete event on Unified Interface

Posted on by 70

I am trying to interrupt the Mark Complete save event for one of our activity entities. I had an existing script which pre Unified Interface worked perfectly, but since we switched to UI it throws an ugly error resulting in a poor user experience.

The error reads: "This form can’t be saved due to a custom setting. Error code: 0x83215605". It does however continue to work as normal after this popup (it still prevents the save and works as normal, just throws an error informing me of the save prevention).

I inserted the below Javascript on the onSave event of a new entity with no other customisations:

function preventSave(executionContext) {
  e = executionContext.getEventArgs();
  e.preventDefault();
  console.log("Save prevented. Save mode: " + e.getSaveMode());
  return;
}

From the console I can see that when I save the form normally (save mode 1) the script still executes and prevents the save, with no error. However, when I mark the record complete (save mode 58) the error message is thrown along with a console warning "Empty string passed to getElementById()" from app.js.

I've tried on multiple entities and multiple forms with the same result. Can anyone else verify that they are able to prevent the saving of activities using Mark Complete without this error occurring? As a secondary query, is there any supported way to hide the error thrown? I'd really appreciate any advice.

Dynamics version info: Server version: 9.1.0000.15631 Client version: 1.4.376-2003.3

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: preventDefault() throws error only on Mark Complete event on Unified Interface

    I had this issue and changed the method to:

    e.preventDefaultOnError();

    Which seemed to remove the error popup for me. 

    Cheers

    Joe

  • samnunn92 Profile Picture
    samnunn92 70 on at
    RE: preventDefault() throws error only on Mark Complete event on Unified Interface

    Hi Johao,

    I was finally able to achieve my requirements by customising the ribbon using the Ribbon Workbench as per your suggestion - thanks! For the benefit of anyone else in the same situation, I created a copy of the 'Mark Complete' button and set up saving handlers inside a Javascript library.

    Kind regards

    Sam

  • Verified answer
    Johao Larios Profile Picture
    Johao Larios 1,795 on at
    RE: preventDefault() throws error only on Mark Complete event on Unified Interface

    Hello,

    I think what you could do is play by hide the save button and make it appear based on some conditions. You could explore that here:

    Also, there are third party tools like ribbon workbench that you could review to perform this.

    docs.microsoft.com/.../customize-commands-ribbon

    regards,

  • samnunn92 Profile Picture
    samnunn92 70 on at
    RE: preventDefault() throws error only on Mark Complete event on Unified Interface

    Hi Johao, thanks very much for your response. I have submitted an idea to Microsoft (https://experience.dynamics.com/ideas/idea/?ideaid=20b32bc1-b578-ea11-99e5-0003ff689747) but was hoping that there would be a more immediate solution. What would you suggest in the mean time? The context is, once a record is closed we need some user input to determine when/if to book another of the same activity. I'd really appreciate any suggestions.

  • Suggested answer
    Johao Larios Profile Picture
    Johao Larios 1,795 on at
    RE: preventDefault() throws error only on Mark Complete event on Unified Interface

    Hello Samnunn95, 

    Thank you for choosing our product. I have checked this and currently this our designed message for this approach on UCI on this scenario. I strongly recommend you submit an idea at https://experience.dynamics.com/ideas/ 

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans