Hello,
That could be done. Here is what you should do:
Use following code and add it to the js webresource:
var HideButton = (function(){
var _isVisible = true;
function isVisible(){
return _isVisible;
}
function onButtonClick(formContext){
_isVisible = false;
formContext.ui.refreshRibbon();
}
return {
IsVisible: isVisible,
OnButtonClick: onButtonClick
};
})();
Add the button, add command, add enable rule of custom type and point it to HideButton.IsVisible from JS Webresource.
Add Action to the button and use HideButton.OnButtonClick function as a onclick handler passing PrimaryControl as a parameter.