locked
How to change attribute requirepment level permanently ? RRS feed

  • Question

  • Hi,

    when I changing required level for a field, it works only when form is open. When I reopen a form, required level returns to default.  How can I change level permanently ?

    this is part of my code

            if (prospectText == valueToTrigger) {
                Xrm.Page.data.entity.attributes.get(attributeToChange).setRequiredLevel("required");
            }
            else {
                Xrm.Page.data.entity.attributes.get(attributeToChange).setRequiredLevel("none");
            }
            Xrm.Page.data.entity.attributes.get(attributeToChange).setSubmitMode("always");

    Wednesday, January 15, 2014 9:17 AM

All replies

  • Hi,

    If you want it's required permanently, go to your solution, edit your field and change its Requirement Level to Business Required. No code involved.

    Hope it helps.

    Wednesday, January 15, 2014 9:21 AM
  • If your field now it must always be required, you can change the behavior from the field properties:

    change it to "Business Required", in this way the field will be always required.
    If  you can't or don't want to change this property, just change your javascript code and remove your if condiition, something like:

    Xrm.Page.data.entity.attributes.get(attributeToChange).setRequiredLevel("required");
    Xrm.Page.data.entity.attributes.get(attributeToChange).setSubmitMode("always");


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, January 15, 2014 9:23 AM
  • My field must be required only if specific value in another field is selected.

    Wednesday, January 15, 2014 9:45 AM
  • Hi,

    At the moment I thought your question is a bit weird, so that's the cause =)).

    I think the following steps is good:

    1. Use your code above in another field OnChange event.

    2. In Form OnLoad, UpdateMode, get another field attribute object then call fireOnChange method.

    Hope it helps.


    Wednesday, January 15, 2014 10:16 AM
  • hi,

     I think your requirement is you have one option set  field.

    If  you select some specific value then only the related field will be required.

    From  the above scenario

    -> First You have the check the condition  for which value the  related field will be required

    ->First You get the option set value and set the required level to be  required.

    function setrequired()

    {

    var op= Xrm.Page.getAttribute("new_opvlaue").getValue()

    if(op==1)

    {

       Xrm.Page.data.entity.attributes.get(attributeToChange).setRequiredLevel("required");
            }
            else {
                Xrm.Page.data.entity.attributes.get(attributeToChange).setRequiredLevel("none");
            }

    }

     You have to call the methods on Onload and on change  events

    you must call the onchange on optioset field.


    Friday, January 17, 2014 11:07 AM
  • Hi, try the following with two options. I hope this will meet your requirement.

    function setToRequired()
    {
    
    
    var v = Xrm.Page.data.entity.attributes.get(TwoOptionField).getValue();
    if(v == 1){
    Xrm.Page.data.entity.attributes.get(YourFieldForRequiredLevel).setRequiredLevel("required");
    }
    if(v == 0){
    Xrm.Page.data.entity.attributes.get(YourFieldForRequiredLevel).setRequiredLevel("none");
    }
    
    
    }

    Friday, January 17, 2014 12:36 PM