how to prevent module editing depending on status 'Completed'

I am a beginner on Sugar...

My target is prevent module editing.

I wrote down ......this.$('.record-edit-link-wrapper').remove(); 
 and it works....
but i want to disabled icon-pencil (it is my biggest problem) on each field ....In order to prevent editing if status is Completed...
How can do it?
Sugar 7.5.1 pro
  • HI. there is group options.,. 
    So create user groups .. group A must see nothing or group b must edit 1 2 3 and group c must delete etc 

    I hope the answer is satisfactory.. I am just busy at the office.. but i will provide a solution a bit later .. 
    In a nut shell.. greate groups of users and enable crud options on roltes and access rules .. 


  • Hi Luca,

    I think you should use dependencies instead of custom javascript: dependencies are made for this kind of features (ie make certain fields read-only, or hide/show fields, when a condition is true)

    Have a look at the Developer Guide:

    Hope this helps,
  • In Sugar 7.5.1 pro you can extend the RecordView and on(render) you can check if this.model.get("status") is "Completed" or not. If is not "Completed" than you can disable or remove the button.
  • HI Luca,
    You can do this by ajax.

    Provide me more details, I 'll try to help you out on this.

    Contact me here below.

    Thanks & Regards
    Sumit Sahay
    skype: sahay786

  • Hi Luca,

    What version of Sugar are you working on?
    There are a lot of ways to do this. 

    If you want the whole record to be not editable, the most simple way I can think of to do this, that works on both 6 and 7, is via "before_save" logichook. In your hook, you can do the condition checking and throw a Sugar Exception to prevent the changes from being saved. 

    If you only want to make some fields not editable, then, dependencies are more suited for the job.


  • My english is bad but i'll try to explain the problem....
    I want to prevent the edit record.

    I made a class with a static function that it returns true if the edit is allowed or it returns SugarException( custom message ) if the status=Clompleted

    I extended module api(/custom/modules/Cases/clients/base/api/) calls my static function

    if (! defined ( 'sugarEntry' ) || ! sugarEntry) die ( 'Not A Valid Entry Point' );

    require_once 'clients/base/api/ModuleApi.php';
    require_once 'data/BeanFactory.php';
    require_once 'custom/modules/Cases/WorkFlow.php';   //<---my class with static function

    class CheckStatusCasesApi extends ModuleApi {

    public function registerApiRest() {
      return array (
        'checkStatusCases' => array (
          'reqType' => 'GET',
          'path' => array('Cases','?', 'check_status_cases'),
          'pathVars' => array('module', 'id','status'),
          'method' => 'checkStatusCases',
          'shortHelp' => 'Formal verification transitional status.',
          'longHelp' => 'custom/modules/Cases/clients/base/api/help/Cases_CheckStatusCasesApi_help.html',
          'exceptions' => array(

      * This method check if the cases status isnt Closed
      * @param ServiceBase $api
      * @param array $args
      * @throws SugarApiExceptionError
      * @return boolean
       public function checkStatusCases(ServiceBase $api, array $args) {
              $id = $args['id'];
              $status = $args['status'];
               $rtnVal = WorkFlowCases::checkStatusChanged( $id, $status );
               if ($rtnVal)
                    return $rtnVal;

                return false;

    It's OK...i suppose.

    In record.js (/custom/modules/Cases/clients/base/fields/rowaction/) i wrote

    ({    extendsFrom: 'ButtonField',

        initialize: function(options) {
   = _.extend({},, {
                'click .rowaction': 'rowActionSelect'
            this._super("initialize", [options]);

         * Triggers event provided at this.def.event on the view's context object by default.
         * Can be configured to trigger events on 'view' itself or the view's 'layout'.
         * @param evt

        rowActionSelect: function(evt) {

            //TODO Add your custom logic

                 var caseID =  this.model.get('id');
                 var status = this.model.get('status');

                  var self = this;

       'GET', app.api.buildURL('Cases/' + caseID + '/check_status_cases'), null, {

                     success: function(data) {

                                  //EDITING IS ALLOWED

                     error: function(error) {

                         //EDITING IS NOT ALLOWED


                     "workflow-status-message", {
                                        level: 'warning',
                                        messages: app.lang.get(error.message , 'Cases'),
                                        autoClose: false


            // make sure that we are not disabled first
            if(this.preventClick(evt) !== false) {
                var target = this.view.context;  // view's 'context' is target by default
                if ( === 'view') {
                    target = this.view;
                } else if ( === 'layout') {
                    target = this.view.layout;
                if ($(evt.currentTarget).data('event')) {
                    target.trigger($(evt.currentTarget).data('event'), this.model, this);


    But it doesn't can i do it?

  • Ciao Luca,

    SugarCRM has a number of “views” that are used to build the page. Record View is the one sugar uses to display all the details of the case. It has a full edit (using the button) and an inline edit (field by field within the display of the details - the pencils you see when you hover on a field indicate which fields are editable inline).

    There may also be other views you need to take care of, mobile views, inline edit in subpanels etc which may become workarounds to editing.

    But let's start with record view, based on Mike Solomon's work (the link I gave you above) to prevent editing you need to work on preventing inline editing and disabling the Edit button in record view: 


    You don’t need an API to check if the Case is closed. You can retrieve field values from within your javascript, inside record.js as long as the page has been rendered.


    will return the contents of the ‘status’ field for that record.

    So to disable inline editing you will create


    on render, you will disable the inline editing if the status is Completed (the custom checkReadonly function), and when the user clicks "Edit" you will pop up a message that "Edit is not allowed for completed Cases" (in the editClicked function).

    (NOTE this code is NOT tested, so there may be errors, always check your console log :) ).

      extendsFrom: 'RecordView',
      initialize: function(options){
          this._super('initialize', [options]);
      checkReadonly: function(){
         var status = this.model.get(‘status');
          if (status == ‘Completed'){ 
                //do not allow inline edit on any fields
                this.editableFields = [];
      editClicked: function(){
        //this overrides an existing event handler when "Edit" is clicked
        //see original at <sugar_root>/jssource/src_files/clients/base/views/record/record.js
        var status = this.model.get(‘status'); //get the status for this record
          if (status == ‘Completed'){ 
              //stop the edit button from being used
              var msg = 'Edit not allowed for Completed Cases';
    ‘case-completed', {
                 level: 'warning',
                 messages: msg,
                 autoClose: true
             return; //goes back to the view without changing to Edit layout
            //allow the edit 
    Hope this helps,
    in bocca al lupo,
  • thank you Francesca,
    I didn't explain it very well

    I need to use my static funtion because i have to respect other conditions
    for example i am not allow to go to back to the status "NEW" if the status is different to "NEW",  so i need to know the previous status  (i retrieve it from my static function and i return the correct message to give to user) and not only the current status ....for this reason i am using
    Please can you give me any advise?....i'm a beginner on Sugar   Ciao
  • You should be able to fit your API into the code I sent above

    Instead of 
        var status = this.model.get(‘status');
        if (status == ‘Completed'){ 
    in each of the functions above use a check on your API call.

    Note that success/error refers to the ability of the API to execute.
    So if your API executes correctly you will have success and the output from the api "data" might be "false" if you are not allowed to edit .

    Inside the success check the output of your API to see if you want to allow edit or not and then use the code inside the if statements to disable the edit.

    You may need to review APIs to make sure you're getting what you want.
    Sorry but I don't have time to go deeper on this right now.