New button in grid calling form

sc_btn_display (‘new’, ‘off’) doesn’t work in production, if it works in development!.

My code with verification of how it passes through the IF (in onScriptInit event) :

 if ([priv_admin_session])
 {
      sc_btn_display ('new', 'on');
      echo 'yes';
 } else {
      sc_btn_display ('new', 'off');
      echo 'no';
 }

Checked with ‘echo’, it correctly goes through where it has to go depending on the true - false value of the global variable [priv_admin_session]. If [priv_admin_session] = true display ‘yes’, if [priv_admin_session] = ‘false’ display ‘no’. But sc_btn_display (‘new’, ‘on’) and sc_btn_display (‘new’, ‘off’) do not work.
The project is implemented with the security module, where in the onValidate event of the Login control the Global variable is set depending on whether the user is privileged or not: [priv_admin_session] = ({rs [0] [0]} == 'Y ')? TRUE: FALSE.
Greetings

Found out the problem.

For anyone who goes through this circumstance:

Although we use sc_btn_display (‘new’, ‘off’) in the Grid to disable the button, if in the security module we have established the form that is linked to the Grid for the User Group to which the active user belongs (although not is Privileged), with the INSERT property to YES, SC in the Grid’s onScriptInit will interpret that this user has enabled the possibility of creating new records, and will prevent the Grid’s new button from being disabled with the sc_btn_display (‘new’, off ').

Therefore, what is established in security in the Applications section in User Groups, the options defined for each Application are above what we do with macros.

That is, if the User has the right to insert, we cannot remove it dynamically, at least in the Grid. It is also true that if we remove the right to insert the NEW button will not appear in the Grid, even if we have established this in the properties of the link with the form.

Anyway what you have to fight.

Greetings
From V5 Professional Edition - October 28, 2011
Up to V9 Professional Edition - January 28, 2022

I am using sc_btn_display to turn off the new button without any problem, it has priority over the security and work as expected

You can hide it manually with jQuery if needed

//onScriptInit

?>
<script>
	$(document).ready(function() {
		$("#sc_b_new_top").hide();
  	});
</script>
<?php

I agree, with jquery you hide the client-side html element, but we are skipping our own security rules. I agree with SC, the button does not appear if in your security rules you establish that the form that links the grid does not have the possibility of inserting records for the group to which the user belongs. And if it is visible if the group the user belongs to allows inserting in the form. No need to work with sc_btn_display, security does it for you.

Greetings

Yes I agree, if it’s OFF because of security we should not play with it

But if it’s ON and for some reason you need to turn it OFF (some external condition not present), sc_btn_display is very usefull

I do use it in the single record form, when the user has selected a record from the Grid and shows it in the form to modify. By having the insert button enabled in the toolbar, it appears next to the Save and Delete buttons. As I only want it to modify or delete the record, I hide the insert button in the onLoad event with sc_btn_display.

Greetings