Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

URL validation using RegEx works in Main form but not in Quick Create

Posted on by 112
I have created the following JavaScript to validate a URL in a URL field on a form then throw an error if the URL is invalid.  I am also
preventing the form from saving if the URL is invalid.  This all works great in the main PowerApps form:
function validateURL() {    var fieldVal = Xrm.Page.getAttribute(/xx_url/).getValue();       var urlPattern = /^https?://////[^//s///$?#]+//.[^//s]*$/;    if (urlPattern.test(fieldVal)) {        // Valid URL        Xrm.Page.ui.clearFormNotification(/urlValidation/);        return true; // Allow the form to save    } else {        // Invalid URL        Xrm.Page.ui.setFormNotification(/Invalid URL!/, /ERROR/, /urlValidation/);        return false; // Prevent the form from saving    }}function onSavePreventInvalidURL() {    if (!validateURL()) {        Xrm.Page.data.entity.addOnSave(validateCancel);    }}function validateCancel(executionContext) {    var saveEvent = executionContext.getEventArgs();    saveEvent.preventDefault(); // Cancel the form save action}// Register onSavePreventInvalidURL as a handler for the /OnSave/ eventXrm.Page.data.entity.addOnSave(onSavePreventInvalidURL);

 

But when I apply the same code to the Quick Create form for the same
table in the same way, the code works for valid URLs but not for invalid
URLs:

  • An error is displayed (correctly)
  • The form does not save (correctly)
  • When the URL is corrected, the Error dissapears (correctly)
  • But the form will not save (incorrectly)

One suggestion was that the Quick Create form may use /states/ differently
to the main form but I really don't know what that means or how it may
affect a fairly simple bit of JavaScript which is working well on the
main form.

I'm relatively new to this so don't know what I am missing.  Any 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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans