0
votes

I am trying to make the Manufacturer field on a CRM Opportunity form become required when a user opens the form. (I cannot simply use a business rule to do this because the Manufacturer field will then become required in QuoteWerks as well, which is where many of our Opportunity records are created.)

I have created a javascript web resource and added to the OnLoad section of the form, but receive the following error when I open the form:

Web Resource Method Does Not Exist: Set Manufacturer To Required.

Below is my code:

function SetManufacturerToRequired() {
    var value = Xrm.Page.getAttribute("new_opportunityscope");
    if (value != null) {
        if (value == "Product") {
            Xrm.Page.getAttribute("new_manufacturer").setRequiredLevel("required");
        } else {
            Xrm.Page.getAttribute("new_manufacturer").setRequiredLevel("none");
        }
    }
else {
        Xrm.Page.getAttribute("new_manufacturer").setRequiredLevel("none");
    }
}

Any help debugging this would be greatly appreciated. Thanks!

2
From My Initial thought, do you have function name SetManufacturerToRequired added correctly when you add it OnLoad Error says that you have attached to onLoad Event but in Webresource it could not find. You probably have added Function name in CRM OnLoad as Set Manufacturer To Required If possible could you please post screenshot of your Edit (Form) and where you add onLoad Event will give more info.AnkUser
@AnkUser, You were correct, thanks! I was calling it "Set Manufacturer To Required" and needed to remove the spaces. The error no longer occurs. However, the field is still not being required when the Opportunity Scope is set to "Product". The web resource is enabled in the "OnLoad" section, but doesn't seem to do anything. Any ideas what could be wrong?Tim G
I added answer to your commentAnkUser

2 Answers

0
votes

For your First Issue,

From My Initial thought, do you have function name SetManufacturerToRequired added correctly when you add it OnLoad Error says that you have attached to onLoad Event but in Webresource it could not find. You probably have added Function name in CRM OnLoad as Set Manufacturer To Required

However, the field is still not being required when the Opportunity Scope is set to "Product".

Try below code, in your original code you are only taking attribute but not it's value

 function SetManufacturerToRequired() {
        var value = Xrm.Page.getAttribute("new_opportunityscope");
        if (value != null) {
            //value.getValue() this will give you value as 777601 or something
if (value.getText()== "Product") {
                    Xrm.Page.getAttribute("new_manufacturer").setRequiredLevel("required");
                } else {
                    Xrm.Page.getAttribute("new_manufacturer").setRequiredLevel("none");
                }
            }
        else {
                Xrm.Page.getAttribute("new_manufacturer").setRequiredLevel("none");
            }
        }
0
votes

Xrm.Page is being deprecated, replace with executionContext.getFormContext()