Opportunity Read Only

I want to make the entire opportunity read-only after the opportunity has been marked closed-won.  What is the best way to do this?

Thank you,

   Jake

Parents
  • Hi Jake Vernon

    Can you check this code and let me know:

    In custom/modules/Opportunities/clients/base/views/record/record.js

    Under Initialize function add following code:

    this.on('render', this.hideAllfields, this); 
    this.events['change input[name=sales_stage]'] = 'hideAllfields';

    Now outside of Initialize function add this code:

    hideAllfields: function(){
              var ssValue = this.model.get('sales_stage');
              if(ssValue == 'Closed Won'){
                   _.each(this.fields, function(field) {                         
                        $('input[name='+field.def.name+']').prop("readonly",true);                
                        $('[data-fieldname="'+field.def.name+'"] input[data-type=date]').prop("readonly",true);                
                        if (_.isEqual(field.def.name, 'sales_stage')) {                           
                             $('input[name='+field.def.name+']').prop("readonly",false);      
                             $('[data-fieldname="'+field.def.name+'"] input[data-type=date]').prop("readonly",false); 
                        }     
                   }, this);
              }else{
                   _.each(this.fields, function(field) {
                        $('input[name='+field.def.name+']').prop("readonly",false);
                        $('[data-fieldname="'+field.def.name+'"] input[data-type=date]').prop("readonly",false);                               
                   }, this);
                   
              }
              
         },

    Hope this Helps..!!

    Best Regards

    S Ramana Raju

  • Hey Angel,

       I used your code and it seems to work great, but how do I add an override permission to it to allow changes to be made by an admin incase there is an error in the closing of the opp?  Does this make sense?

  • Hey Angel,

         I have another question for you.  How can I apply what you did with the read-only and make it so that a user trying to view a lead that is not assigned to them or the lead is not assigned to pooluser(this is a username we use for all leads uploaded by a data or admin user), they can't edit it or view certain lead information, like phone number and email address?  But we do want managers and marketing for example to be able to see this data.

    Any ideas?  Did I explain this well enough?

  • You should be able to configure some of that via the use of Roles. For example, you could define a role where the fields you specified cannot be edited except by the owner of the record.

    The pooluser scenario would require code similar to the one you've used for Opportunities as Roles wouldn't allow you to define criteria. 

    For that, you could create a record.js in ./custom/modules/Leads/clients/base/views/record/ and adjust the criteria for the IF to something like this:

    if (this.model.get('assigned_user_name') != 'pooluser')

    The key to making the field non-editable is to add the name of the field to the array noEditFields. For example, I could make the status field from the Leads module non-editable with this line:

    this.noEditFields.push('status');

    Hope that helps.

Reply
  • You should be able to configure some of that via the use of Roles. For example, you could define a role where the fields you specified cannot be edited except by the owner of the record.

    The pooluser scenario would require code similar to the one you've used for Opportunities as Roles wouldn't allow you to define criteria. 

    For that, you could create a record.js in ./custom/modules/Leads/clients/base/views/record/ and adjust the criteria for the IF to something like this:

    if (this.model.get('assigned_user_name') != 'pooluser')

    The key to making the field non-editable is to add the name of the field to the array noEditFields. For example, I could make the status field from the Leads module non-editable with this line:

    this.noEditFields.push('status');

    Hope that helps.

Children
No Data