Model driven apps field validation javascript error

46 Views Asked by At

I'm looking for validate emails in a multi line text field using js. I have attached the code here. I'm getting error that web resource method does not exist: new formOnLoad.

    function valemail(executionContext){ 
        var validateEmails = 
        {
            Context: null,
            checkEmails: (emailString) => 
            {   
                var formContext = validateEmails.Context;
                var emails = emailString.split(';');
        
                // Regular expression for email validation
                var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
        
                // Validate each email address
                for (let i = 0; i < emails.length; i++) {
                    var email = emails[i].trim(); // Remove leading/trailing whitespaces
        
                    if (!emailRegex.test(email)) {
                        console.error(`Invalid email address: ${email}`);
                        formContext.getControl("new_brokeremailaddresses").setNotification(`Email not Valid : ${email}`);
                    }
                }
            },
            execute: (executionContext) => 
            {
                var formContext = executionContext.getFormContext();
                validateEmails.Context = formContext;
                if(formContext.getAttribute("new_brokeremailaddresses"))
                {
                    var emailString = formContext.getAttribute("new_brokeremailaddresses").getValue();
                    if(emailString != null)
                    {
                        validateEmails.checkEmails(emailString.toString());
                    }
                }
            }
        }
    
    }

error

ReferenceError: Web resource method does not exist: new.formOnLoad

Error Details:
Event Name: onload
Function Name: new.formOnLoad
Web Resource Name: new_ValEmailScript
Solution Name: Active

Any suggestion where it need modification or technical issue to correct.

Thanks.

0

There are 0 best solutions below