Skip to main content
Post a question

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

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

Like (1) ShareShare
ReportReport
Posted on 30 Sep 2024 13:26:55 by 2
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());
            }
        },
    }
)
AccountScripts.js
  • Suggested answer
    Ben356 Profile Picture
    Ben356 13 on 04 Oct 2024 at 13:59:45
    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 02 Oct 2024 at 11:34:34
    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

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,575 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Loading complete