Question

Hide DELETE button on condition

Hello,

 

I'm trying to make the DELETE button on Lead to be available only for certain users. This is my code:
 

In diff:

 

In methods:


In console IsDeleteButtonVisible appears as true, but the button is hidden no matter what.

Like 0

Like

9 comments

Change events to attributes bound in row action buttons do not occur. So changing the attribute won't change the button's properties. The only way I've been able to accomplish this is to override the onRowAction with tag delete to display a message if the action is not allowed. I've also hidden that using some conditional CSS as well, but that route is a bit hacky.

Ryan

You can hide the "delete button" on the detail inheriting from Detail Schema where you need, and add some of the following pieces of code to remove New, Copy, Delete & Edit

 

If you also want to remove delete in Methods, just need to add:

 

// remove the delete option
			getDeleteRecordMenuItem: Terrasoft.emptyFn	  

 

define("NdosSchema26d0e559Detail", [], function() {
	return {
		entitySchemaName: "NdosProductosServiciosRequisionCompra",
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
		methods: {
			// Remove New record
			getAddRecordButtonVisible: function() {
				return false;
 
			},
 
			// remove the edit option           
			getEditRecordMenuItem: Terrasoft.emptyFn,
 
			// remove the copy option
			getCopyRecordMenuItem: Terrasoft.emptyFn,
 
			// remove the delete option
			getDeleteRecordMenuItem: Terrasoft.emptyFn	          
        }
	};
});

 

Regards

Julio

Julio Falcon (Cibernética),

True, as Julio says, you can hide it so it is not shown at all, but you cannot conditionally hide it. Actually, I was thinking you can't change the visible value for it at runtime (since it doesn't respond to change events). However, the current user isn't going to change, so you could use the approach of using an attribute as long as the attribute is set BEFORE the detail grid is rendered. You'd need to somehow pre-fetch that the user is in the role (like from MainHeaderSchema when they first log in), and add it to the Terrasoft.SysValues so it's retrievable without doing an ESQ, then you could set it easily in the detail's init.

Ryan

Ryan Farley,

 

Ryan, how can disable/delete the option in the same detail to select multiple records? Can help me, please?

 

Thanks

Julio

Julio.Falcon_Nodos,

Not 100% sure if this is all that is needed, so you'll have to test, but looks like it might work to add the following to disable multiselect (which means you can't delete multiple at once): 

init: function() {
	this.callParent(arguments);
	this.set("MultiSelect", false);
}

Ryan

Ryan Farley,  Julio Falcon (Cibernética),

I actually found a way to do this with your help. 
I kept the function that checks when the button should be displayed and changes the attribute value, but instead of trying to set the button through diff I called another function that sets the attribute through CSS.



 

Ryan Farley,

Thanks Ryan,

 

It didn't works :-(

 

Also what really I want to do is to know how can I detect the multiple deletion signal in a process, to recalculate the result regarding the records remaining in the detail, so If I didn't how to detect this, I found the best option is to inactivate the "Select multiple records" option in the detail menu

 

Ryan Farley,

I'm also try another approaches, but without results, to hide the "Select multiple records" menu option :-(

 

Based on article on https://community.creatio.com/questions/remove-new-and-import-buttons-lookup-object

 

define("NdosSchema82b72e2cDetail", [ "ConfigurationConstants" ], function(ConfigurationConstants) {
	return {
		entitySchemaName: "NdosDetalleDeCotizaciones",
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
		methods: {
          init: function() {
         	this.callParent(arguments);
            this.getSectionActions();
          },
 
            getSectionActions: function() {
            	var actionMenuItems = this.callParent(arguments);
                //var itemToRemove = [];
            	actionMenuItems.each(function(item) {
            		if (item.values.Caption === "Resources.Strings.MultiModeMenuCaption" )  { //"Seleccionar varios registros" || item.values.Caption == "Select multiple records") {
            			item.values.Visible = false;
                      //item.values.Enabled = false;
                        //itemToRemove = item;
                      //itemToRemove.push(item);
 
            		}
            	});
                //actionMenuItems.remove( itemToRemove );
            	return actionMenuItems;
            }, 
 
            /* Delete the [Copy] menu item. */
            getCopyRecordMenuItem: Terrasoft.emptyFn,
 
          /* Delete the [Edit] menu item. */
            getEditRecordMenuItem: Terrasoft.emptyFn,
 
        }
	};
});

Ryan Farley,

Hi Ryan

 

Solved, the solution was shared by Pavlo Sokil and it's posted on article on https://community.creatio.com/questions/there-any-way-detect-process-wh…

Show all comments