Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Web Resource Method does not exist

Posted on by 4
I have a basic javascript on the form:
 
Script:
function setMandatory(executioncontext)
{
    var formContext=executioncontext.getFormContext();
    var mandatoryField = formContext.getAttribute("cr65f_setmandatory").getValue();
    if(mandatoryField==230660000)
    {
        formContext.getAttribute("cr65f_firstname").setRequiredLevel("required");
        formContext.getAttribute("cr65f_lastname").setRequiredLevel("none");
    }
    else if (mandatoryField==230660001)
    {
        formContext.getAttribute("cr65f_lastname").setRequiredLevel("required");
        formContext.getAttribute("cr65f_firstname").setRequiredLevel("none");
    }
    else
    {
        formContext.getAttribute("cr65f_firstname").setRequiredLevel("none");
        formContext.getAttribute("cr65f_lastname").setRequiredLevel("none");
    }
        
}
 
But when i trigger it. 
Iam getting error:
i tried multiple times publishing the form but no luck. please help.
Categories:
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 7,797 Super User 2024 Season 1 on at
    Web Resource Method does not exist
    The error you're encountering typically suggests that the function setMandatory is not correctly referenced in your form or that there is an issue with how the script is set up in Dynamics 365. Here are some steps you can try to resolve this issue:
     
    1. Verify Script Registration:
     
    Go to the form editor for the entity where you're using this script.
     
    In the form editor, select Form Properties.
     
    Ensure that the cr65f_JSPraticeScripts web resource is added in the Form Libraries section.
     
    In the Event Handlers section for the field’s OnChange event, make sure that:
     
    The Library is set to cr65f_JSPraticeScripts.
     
    The Function is set to setMandatory (make sure there are no typos).
     
    Pass execution context as first parameter is checked.
     
    2. Check Script Syntax:
     
    Double-check that your JavaScript function syntax is correct, especially in the function name and parameter. The function you've posted looks correct, but any minor typo or syntax error could cause this issue.
     
    3. Clear Browser Cache:
     
    Sometimes, old versions of scripts get cached in the browser, which can cause errors even after publishing the latest version.
     
    Clear your browser cache or try running the script in an incognito window after publishing.
     
    4. Publish All Customizations:
     
    Instead of publishing only the form, try going to Solution and clicking on Publish All Customizations. This ensures all scripts are updated across the environment.
     
    5. Add a Test Alert for Debugging:
     
    Insert an alert statement in the function to confirm if the script is being executed.
     
     
    function setMandatory(executioncontext) {
        alert("Script triggered");
        var formContext = executioncontext.getFormContext();
        var mandatoryField = formContext.getAttribute("cr65f_setmandatory").getValue();
        // rest of your code...
    }
     
    This can help confirm if the script is running but encountering an issue elsewhere.
     
    6. Enable Script Debugging:
     
    If you’re still having issues, enable script debugging in your browser (e.g., F12 in Chrome) to see if there are specific errors being logged in the console.
     
    Following these steps should help you troubleshoot the issue. Let me know if the problem persists after these checks.
  • Web Resource Method does not exist
    Your JavaScript looks okay, but two things comes to mind:
     
    Have you enabled "Pass execution context as first parameter" in your event handler?
    executioncontext should be executionContext; Although I'm not 100% sure it's the reason why, it's best practices to use camelCase and JavaScript is case sensitive.
     

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,316 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans