I have a javascript function which is calculating a score based on the data entered in a number of fields. I'm doing this by looping through all the fields on a form, checking the values for attributes and keeping a running score. When I publish the first example, I get no error and the data is right. When I publish the second, I get this error (screenshot below): "Web resource method does not exist: SetRelationshipStrength". I can't see anything syntaxually incorrect. Is there some limitation that I can't seem to find documented? I've encountered this mostly when there is a syntax issue in the script, but don't see that in this.
Good Example
Hi,
Sorry I didn't see your last post.
No, the trial versions give you all the capabilities to test the product properly, including the development of web resources.
Yes, special characters can be one of the causes too...that's why I asked which code editor you are using on one of the above posts.
Anyway I'm glad that you managed to find a logical explanation for your problem.
Closing as I figured it out. There were some special characters hidden in the cases that failed. Either replacing them with a proper space or rekeying the case worked. My guess is the editor for comments does this by default which is why those helping had no issue.
One thing I didn't add. This is in a trial environment. Would that make a difference? Again, I can't find anything documented about limitations, but I guess possible.
I originally did it in Notepad++ given how simple it was. I did the most recent in VS Code.
Hi Zach,
I did the same thing on my environment. I don't get the error as you do. Which editor do you use to write your code?
Here they are. I have a few more debugging things to try with rearranging cases to identify a bit more closely where the issue might be.
Form Properties
Header Resource Content
Handler Properties
Hi Zach,
I just checked on my side and there is no problem with the web resource. The only thing left to do is to check your configuration for the Handler events. Could you please share a screenshot of your configuration.
Thanks Mehdi - I did was you suggested and receive the exact same error. I removed all comments frmo the switch statement so all cases were in the new web resource. Just for reference, added the code below. As for Xrm.Page, I planned to update that. Just got hung up on this error before getting to the end of the code. I did validate the form is using the new web resource and the function name was copied and pasted. The below is the entirety of the js file.
function SetRelationshipStrength(executionContext) {
var formContext = executionContext.getFormContext(); // get the form context
var score = 0;
formContext.data.entity.attributes.forEach(function (attribute, index) {
var attr = attribute.getName();
var value = formContext.getAttribute(attr).getValue();
if (formContext.getAttribute(attr).getAttributeType() === "optionset") {
var value = formContext.getAttribute(attr).getText();
}
else {
var value = formContext.getAttribute(attr).getValue();
}
switch (attr) {
case "firstname":
if (value != "" && value != null) {
score = score + 2;
}
break;
case "jobtitle":
if (value != "" && value != null) {
score = score + 1;
}
break;
case "cre5e_jobtype":
if (value != "" && value != null) {
switch (value) {
case "Technical":
score = score + 2;
break;
case "Functional":
score = score + 2;
break;
}
}
break;
case "cre5e_keybusinessinterests":
if (value != "" && value != null) {
score = score + 1;
}
break;
case "telephone1":
if (value != "" && value != null) {
score = score + 2;
}
break;
case "emailaddress1":
if (value != "" && value != null) {
score = score + 1;
}
break;
case "managername":
if (value != "" && value != null) {​
score = score + 2;
}​
break;
case "cre5e_hasdirectreports":
if (value != "" && value != null) {​
score = score + 2;
}​
break;
case "cre5e_favoritesport":
if (value != "" && value != null) {​
score = score + 3;
}​
break;
case "cre5e_favoritefood":
if (value != "" && value != null) {​
score = score + 2;
}​
break;
}
/*if (value != "" && value != null && attr == "firstname") {
score += 2;;
}
if (value != "" && value != null && attr == "jobtitle") {
score += 5;
}*/
});
Xrm.Page.getAttribute("cre5e_relstrengthtest").setValue(score);
Xrm.Page.getAttribute("cre5e_relstrengthtest").setSubmitMode("always");
}
Hello,
I compared both versions in Visual Code, tried each one individually, and they are also working for me. Please try again with a web resource created from scratch.
Please avoid Xrm.Page functions. When developing for v9 you should follow the new Client API documentation: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference
The Visual Code extension suggested by Mehdi can help you on using only supported functions since it's based on the JavaScript code snippets for Dynamics 365 Customer Engagement v9.
Hope this helps you.
Please mark the answer as verified if helpful. That will help others in future.
Hi,
I have copied your code, it works without any problem for me. The problem is not about your function, I think the problem is about the
whole web resource.
I suggest that you create a new web resource that will contain the SetRelationshipStrength function only.
Another thing, avoid using Xrm.Page which is deprecated. You should use the following methods:
There is an extension on Visual Studio Code that will help you to use the latest version of the client API:
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156