Search code examples
dynamics-crmmicrosoft-dynamicsdynamics-crm-2013

Is there a way to make a field in Dynamics CRM as one time entry field?


Basically, what I want is that the user should be able to select the dropdown and not be able to change it after making and saving the selection. So it will be a one-time entry field.

Below is a screenshot of the field I want to apply this property.

photo

So this field has a Yes or No selection. And to make the business logic from failing I have to make it a one-time entry field only.

I looked up the form editor for possible things but couldn't find anything that would let me achieve this.

UPDATE #1

Below is my onload function:

function Form_onload() {
    var formType = Xrm.Page.ui.getFormType();
    var p = Xrm.Page.getAttribute("opportunityid");
--------------NEW CODE--------------------------------

    if(formType ==2){ //form type 2 means the form is a saved form. form type 1 is new form.

    alert(formType);
    var myattribute = Xrm.Page.getAttribute("var_internal");
    var myname = myattribute.getName();
    if (Xrm.Page.getControl(myname) != null) {
        //alert(myname);
        Xrm.Page.getControl(myname).setDisabled(true);
    }
    }
--------------NEW CODE---------------------------
    if (formType == 1 && p != null && p.getValue() != null) {
        alert('Child Opportunities can only be created by clicking the Create Child Opportunity button in the Opportunity ribbon.');
        window.top.close();
    }


}

Solution

  • Due to environment-specific settings in my DEV, I was not able to reproduce what was suggested by @Eccountable. Although, his solution worked in other environments.

    @AnkUser has a good answer as well but I was looking to shorten the code and make things as simple as possible.

    My solution

    I was able to handle this using Javascript on client-side. using the XRM toolbox.

    In the XRM toolbox, I located the javascript for the opportunity and observed field changes in formType when the Opportunity was New and when the Opportunity was Existing. This variable (formType) was =1 when the Opportunity was New and =2 when it was Existing/Saved.

    Using this piece of information I was able to leverage my Javascript as follows in Form_onload()

    function Form_onload() {
        if (formType == 2) {
            var myattribute = Xrm.Page.getAttribute("internal");
            var myname = myattribute.getName();
            if (Xrm.Page.getControl(myname) != null) {
                Xrm.Page.getControl(myname).setDisabled(true);
            }
        }
    }