2
votes

I am working on the Opportunity form in CRM 2011.

I have 2 fields I am working with: azdb_payment1type & new_payment1cclast4orcheckgc

azdb_payment1type has option set values:

  • Visa = 807,370,000
  • Mastercard = 807,370,001
  • American Express = 807,370,002
  • Discover = 807,370,003
  • Check = 807,370,004
  • Cash = 807,370,005
  • Credit Rollover = 807,370,006

IF the value of this field (azdb_payment1type) is 807,370,004 or less, I'd like to REQUIRE that the new_paymentcclast4orcheckgc field is filled out.

I created a function for the azdb_payment1type field called "requireCClast_onchange", then added the below code to the form's main library:

function requireCClast_onchange() {
  var payment1type = Xrm.Page.getAttribute('azdb_payment1type').getValue();
  alert(payment1type);
  if (payment1type <= '807,370,004') {
    Xrm.Page.getAttribute("new_payment1cclast4orcheckgc").setRequiredLevel("required");
  }
}

With the code inserted as onchange, nothing happens when I select a CC, then tab off the field. If I change the function to onsave, then edit the library with the changes, it DOES return the alert I set up in the code, but it doesn't change the Requirement Level from "Business Recommended" to "Required".

Is this even possible with Javascript?

1

1 Answers

0
votes

I would have a look at this line. payment1type <= '807,370,004'

You are comparing a number to a string, I'm not sure have JavaScript will resolve that but I can't imagine its the way you would want.

I believe you should be doing, payment1type <= 807370004