Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Web Resource doesn't e...
Sales forum
Suggested answer

Web Resource doesn't exist - Stuck with this problem for a week

Posted on by
I'm getting this Script Error when I'm trying to wire my JS file to my CRM:
 
ReferenceError: Web resource method does not exist: NameOnChange
    at b._handleMethodNotExistError (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:1272803)
    at b.execute (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:1271391)
    at https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:4:121402
    at i (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:97179)
    at re._executeIndividualEvent (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:4:121376)
    at re._executeEventHandler (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:4:118194)
    at Object.execute (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:4:117584)
    at w._executeSyncAction (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:623113)
    at w._executeSync (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:622840)
    at w.executeAction (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:622622)
    at t.dispatch (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:627959)
    at Object.dispatch (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:900934)
    at dispatch (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:627448)
    at Object.execute (https://content.powerapps.com/resource/uci-infra-bus/scripts/17.1dcb02d7db3115cf5c29ee4703a12049.js:4:19354)
    at w._executeSyncAction (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:623113)
    at w._executeSync (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.9bfa873a8412319c44f38e34756503b6.js:14:622840)
Error Details:
Event Name: onchange
Function Name: NameOnChange
Web Resource Name: new_AccountScripts
Solution Name: Active
Publisher Name: DefaultPublishereversourcedev
 
This is my code which I isolated into a separate file:
var Sdk = window.Sdk || {};
(
    function () {
        this.formOnLoad = function (exeuctionContext) {
        },
        this.NameOnChange = function (executionContext) {
            const firstName = formContext.getAttribute("firstname").getValue();
            const lastName = formContext.getAttribute("lastname").getValue();
            const middleName = formContext.getAttribute("middlename").getValue();
            const nameRegex = /^[a-zA-Z]+$/;
            let isValid = true;
            formContext.getControl("firstname").clearNotification();
            formContext.getControl("lastname").clearNotification();
            formContext.getControl("middlename").clearNotification();
            let isfieldModified = false;

            if (firstName && !nameRegex.test(firstName)) {
                formContext.getControl("firstname").setNotification("First Name contains invalid characters");
                isValid = false;
            }
            if (lastName && !nameRegex.test(lastName)) {
                formContext.getControl("lastname").setNotification("Last Name contains invalid characters");
                isValid = false;
            }
            if (middleName && !nameRegex.test(middleName)) {
                formContext.getControl("middlename").setNotification("Middle Name contains invalid characters");
            }
            if (isValid && isfieldModified) {
                formContext.getAttribute("eve_fieldmodified").setValue(new Date());
            }
        },
    }
)
Categories:
AccountScripts.js
  • Suggested answer
    Ben356 Profile Picture
    Ben356 6 on at
    Web Resource doesn't exist - Stuck with this problem for a week
    Hello,
     
    I have used this code to reproduce the error
     

     
    The namespace "Sdk" that was declared on top needs to be called at the end.
     
    Correct code.

     
    In addition:
    • remember to declare formContext before using it
    • The function should be called with its name space when creating the event
     

    Hope that fixes the error.
     
  • Suggested answer
    SteRe Profile Picture
    SteRe 13 on at
    Web Resource doesn't exist - Stuck with this problem for a week
    Hi 
    I did not check the whole script in detail if there are semicolon missing or something else but pretty obvious is this. 
    You use executionContext as parameter and later on formContext. But you never declare formContext. Add this
    var formContext = executionContext.getFormContext();
    at the beginning of your function NameOnChange. 
     
    Further some general hints. To use this script you need to create a web resource and publish it. Even when you change something, after every upload you need to publish again. Further you need to add the web resource to form libraries and add some events. As you are getting an error I guess you did this part, but did you also publish before?

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans