I have created a web resource that is supposed to set a field to "required" when the form is opened. I have added the web resource to the OnLoad section of the form. However, it is not setting the field to required. (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.)
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 ideas why its not working and how I can fix it?
Thanks!
*This post is locked for comments
Hi,
Please try following code:
function SetManufacturerToRequired(){
var value = Xrm.Page.getAttribute("new_opportunityscope").getValue();
if(value != null && value="Product"){
Xrm.Page.getAttribute("new_manufacturer").SetRequiredLevel("required");
}else{
Xrm.Page.getAttribute("new_manufacturer").SetRequiredLevel("none");
}
}
First of all, Xrm.Page was deprecated. You have to use formContext in order to work with attributes correctly.
In addition, getAttribute() returns attribute object for you, not a value. You should add getAttribute('field').getValue() in order to get field value.
Hi There,
Have you tried to set required level directly from the console ?
Simply try to debug on console form (Press F12 on CRM form) to set required level.
It supposed to work
Hi,
var value = Xrm.Page.getAttribute("new_opportunityscope");
I think you have to do Xrm.Page.getAttribute("new_opportunityscope").getValue() to actually get the value. With only getAttribute() you will only retrieve the object so the clause if (value == "Product") will always be false, probably that's why your required level is always as "none".
Best regards
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,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156