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

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Custom JS code on Save not working

(1) ShareShare
ReportReport
Posted on by
I am exploring things in model driven apps using js, so i want to validate the form using basic validation like is the fields empty etc. So I have a js code on form save but when i select save button for the first time without filling anything the errors show up (using set notification error code in js) but after I fill the field and click on submit, the code is not triggering again. I used the same code and instead of set notification i used alerts there it works fine but set notification thing doesn't work. Any idea what am i doing wrong. Here the code snippet.
 
function validateLeaveOnSubmit(executionContext) {
    var formContext = executionContext.getFormContext();
    var eventArgs   = executionContext.getEventArgs();
    var hasErrors   = false;
    var dummyCtrl = formContext.getControl("sm_dummy");
    dummyCtrl.clearNotification("sm_dummy_req");
    var dummyAttr = formContext.getAttribute("sm_dummy");
    var dummy     = dummyAttr.getValue();
    if (dummy === null) {
        dummyCtrl.setNotification("Please enter dummy value.", "sm_dummy_req");
        hasErrors = true;
    }
    if (hasErrors) {
        eventArgs.preventDefault();
    }
}
Categories:
I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 69 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 61

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 54 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans