Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

New business rule on existing opps

Posted on by Microsoft Employee

Hi - I created a business rule that works fine on new opportunities setting a field as required. (I just want it on this form, not globally.) However, on existing opps this doesn't work. Any ideas? Thanks

03680.Capture.JPG

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: New business rule on existing opps

    Well, that's why I suggested to just remove those lines - thought it would be easier if you don't use JS too often:)) But you've figured out how to comment them out, so it's all good.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: New business rule on existing opps

    Alex - thank you. I commented out the two lines and the field is now always required. Learned something new also, although I don't understand the JS. When I copied the form which contained the JS, the fields were never required until I attached the business rule that does the same thing. I'm not a developer so I'm not confident just removing it.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: New business rule on existing opps

    I think you've found the problem.. In the ComputeRequiredFields there are two calls which will reset required level for the delivery organization. If you are switching to the business rules, here is what I would probably do:

    - Create a copy of that form (save for as etc) so you don't break the original

    - In the CRM form designer, go to the "Form Properties" and remove all event handlers from the Form "Onload"

    - Save and publish

     You'll likely need to recreate some of what the javascript is doing in the business rules after that

    Or, you might simply remove these two lines from the javascript web resource:

    Xrm.Page.getAttribute('new_deliveryorganization').setRequiredLevel("recommended");

    and

    Xrm.Page.getAttribute('new_deliveryorganization').setRequiredLevel("none");

    Then save and publish all.

    This will take care of that particular field, but the javascript will still be running for other fields

  • Suggested answer
    Walespop Profile Picture
    Walespop 520 on at
    RE: New business rule on existing opps

    Hi, it's all in the JavaScript code. There is already a function that set the required level from ComputeRequiredFields function

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: New business rule on existing opps

    I found this on the form under Events. I don't know JS but it looks like it is setting field requirements that are being accomplished with a business rule. My guess is this is from our old version. How can I tell if this is still active?

    function Form_onload() {

       Xrm.Page.getAttribute("stepname").setSubmitMode("always");

       Xrm.Page.getAttribute("new_enddatecalculated").setSubmitMode("always");

       ComputeRequiredFields();

    }

    function DisablePriceList() {

    var PriceList= Xrm.Page.data.entity.attributes.get("pricelevelid");

    PriceList.setRequiredLevel("none");

    }

    function ComputeEndDate() {

       if (Xrm.Page.getAttribute("new_startdate").getValue() == null || Xrm.Page.getAttribute("new_durationinmonths").getValue() == null) {

           Xrm.Page.getAttribute("new_enddatecalculated").setValue(null);

           return;

       }

       var startDate = Xrm.Page.getAttribute("new_startdate").getValue();

       var duration = parseInt(Xrm.Page.getAttribute("new_durationinmonths").getValue(), 10);

       if (duration >= 0) {

           startDate.setMonth(startDate.getMonth() + duration);

           Xrm.Page.getAttribute("new_enddatecalculated").setValue(startDate);

       }

    }

    function ComputeRequiredFields() {

       if (Xrm.Page.getAttribute("new_probability").getValue() >= 4) {

           Xrm.Page.getAttribute('new_startdate').setRequiredLevel("recommended");

           Xrm.Page.getAttribute('new_billingterms').setRequiredLevel("recommended");

           Xrm.Page.getAttribute('new_durationinmonths').setRequiredLevel("recommended");

           Xrm.Page.getAttribute('new_deliveryorganization').setRequiredLevel("recommended");

           Xrm.Page.getAttribute('estimatedvalue').setRequiredLevel("recommended");

           Xrm.Page.getAttribute('estimatedclosedate').setRequiredLevel("recommended");

       } else {

           Xrm.Page.getAttribute('new_startdate').setRequiredLevel("none");

           Xrm.Page.getAttribute('new_billingterms').setRequiredLevel("none");

           Xrm.Page.getAttribute('new_durationinmonths').setRequiredLevel("none");

           Xrm.Page.getAttribute('new_deliveryorganization').setRequiredLevel("none");

           Xrm.Page.getAttribute('estimatedvalue').setRequiredLevel("none");

           Xrm.Page.getAttribute('estimatedclosedate').setRequiredLevel("none");

       }

    }

    function new_probability_onchange() {

       var probability = (Xrm.Page.getAttribute("new_probability").getValue()) ? Xrm.Page.getAttribute("new_probability").getValue().toString() : "";

       switch (probability) {

           case '2':

               Xrm.Page.getAttribute("stepname").setValue('Prospect 10%');

               break;

           case '3':

               Xrm.Page.getAttribute("stepname").setValue('Qualify 25%');

               break;

           case '4':

               Xrm.Page.getAttribute("stepname").setValue('Cover the Bases 50%');

               break;

           case '5':

               Xrm.Page.getAttribute("stepname").setValue('Present Solution 75%');

               break;

           case '6':

               Xrm.Page.getAttribute("stepname").setValue('Confirm 90%');

               break;

           case '7':

               Xrm.Page.getAttribute("stepname").setValue('Booked');

               break;

           default:

               Xrm.Page.getAttribute("stepname").setValue('');

               break;

       }

       ComputeRequiredFields();

    }

    function new_startdate_onchange() {

       ComputeEndDate();

    }

    function new_durationinmonths_onchange() {

       ComputeEndDate();

    }

    function stepname_onchange() {

    }

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: New business rule on existing opps

    There are no javascript customizations linked to the form? Is it possible that the field is set to not required in the javascript?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: New business rule on existing opps

    That's correct. Even for new ones where the field was required, I can re-open them and blank out the field. The field is an option set if that makes a difference.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: New business rule on existing opps

    So.. that's for the new opps.. Just so I understand.. For the already existing opportunities, when you open them, the name is populated, it's still exactly the same form, but the field is not set as required. Right?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: New business rule on existing opps

    Name is required and Delivery org isn't starred as required until I enter the name.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: New business rule on existing opps

    Hi kbearhome,

     I guess I'm just trying to confirm if the form you are looking at is the form that rule applies to(don't see form name on the original screenshot). Parts of the form that would be interesting are:

    - Form name at the top left corner - if it matches the form name for the rule

    - Opportunity name field (if there is a value)

    - Delivery organization field (if it's required or not)

     If you've checked all that, just ignore it, though.

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans