Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

324
Views
preventDefault not working correctly Dynamics 365

I am trying to get my form to give an alert and prevent save if it meets a certain criteria (the if statement) and save if anything else but if I stick preventDefault inside the IF it still allows me to save.

I have tried putting it outside the IF but then no matter what I can't save the form and my formContext.data.save() doesn't work.

function denyCreateVariationSor(executionContext)
{
    debugger;

    var id = Xrm.Page.getAttribute("gilm_variation").getValue()[0].id;
    
    var url = 'gilmartins-test.crm11.dynamics.com/.../gilm_variations eq ' + id + ')';
    var variationStatus;
    
    var formContext = executionContext.getFormContext();
    
    fetch(url).then(response => response.json()).then(data =>
    {
        var arr = data.value;
        variationStatus = arr[0]["gilm_variationstatus"];

        if (variationStatus != 870110000)
        {
            executionContext.getEventArgs().preventDefault();
            alert("You can't add a SOR onto a completed/cancelled variation");
        }
        else
        {
            formContext.data.save()
        }
    });
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!