Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

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

(1) ShareShare
ReportReport
Posted on by 20
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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Product updates

Dynamics 365 release plans