Skip to main content

Notifications

Announcements

No record found.

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

Web Resource Method does not exist

(3) ShareShare
ReportReport
Posted on by 8
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 8,699 Super User 2024 Season 1 on at
    Web Resource Method does not exist
    Hello User are you still facing the problem?
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 8,699 Super User 2024 Season 1 on at
    Web Resource Method does not exist
    Also check if you are adding this function in correct web resource.
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 8,699 Super User 2024 Season 1 on at
    Web Resource Method does not exist
    Last option is to debug your code.
     
    Remove most of the code and just Get form context and then debug your code. If you are able to get formcontext that means there are some issues on remaining code. 
     
    Add lines after lines and follow same debug process.
     
  • CU06110524-0 Profile Picture
    CU06110524-0 8 on at
    Web Resource Method does not exist
    Hi @Amit Katariya,
     
    Thanks for your response.
     
    I tried all the steps mentioned unfortunately, none of them worked. I have also written other simple function that also is falling with the same error. I even written try catch function to check any error but that was also not getting triggered. Published multiple times.
     
    function :
     
    function populateFullName(executionContext)
    {
        try
        {
            var formContext= executionContext.getFormContext();
        var firstName = formContext.getAttribute("cr65f_firstname").getValue();
        console.log("First name " + firstName)
        
        var lastName = formContext.getAttribute("cr65f_lastname").getValue();
        console.log("Last name"+lastName)
        if(firstName==null)
        {
        firstName="";
        }
        if(lastName==null)
        {
        lastName="";
        }
        var fullName= firstName+" "+lastName;
        formContext.getAttribute("cr65f_name").setValue(fullName);
        }
        catch(error)
        {
            console.log("Error Setting full name ",error.message);
            alert("An error Occured while setting full name "+error.message);
        }
    }
     
    Error :
    Configaration :
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 8,699 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

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,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans