sc_field_display in a form

I have this code on a Detail-Form (Editable Grid View) on Event onScriptInit:


if ($_SESSION['user']['groupid'] < 3)
{
 sc_field_display({Field1}, 'on');
 sc_field_display({Field2}, 'on');
}
else
{
 sc_field_display({Field1}, 'off');
 sc_field_display({Field2}, 'off');
}

When the User with GroupID >= 3 clicks on the icon for new record, sc_field_display({<fieldname>}, ‘off’) is not working and the “off-Fields” are displayed! The labels for the fields are (correct) not displayed. Why?

Re: sc_field_display in a form

Your code looks right …

I would test your session var and see if it is populated:
if(!isset($_SESSION[‘user’][‘groupid’])) {
// exit to login screen
} else {
// your posted code here
{

or add vardump($_SESSION[‘user’]) to your code and it will echo to the screen.

-take a look at the generated code in your form. It is creating some code that PHP does not like?
-check the case and field name? try quoting the {fieldname} or double quoting both the field name and condition as sc_field_display("{field}",“off”)
-is there code above this or in AppInit that does not allow this to execute?

generated code can create scripting code errors sometimes.

Regards,
Scott.

Re: sc_field_display in a form

I believe that your code should be in the event onLoad … can you test?

Re: sc_field_display in a form

@Scott:
Make the sample code simple … :wink: (i test the session var in the original code).

@Diogo:
Bingo! In Event onLoad it works … Thanks!

Can you explain, why? In the WebHelp (ScriptCase Macros / Macros x Applications) is both correct …

Re: sc_field_display in a form

I would like to know why onLoad was required, as I understand, onLoad should be for using values in the form fields if needed. onInit should be to set options to the form before. I have plenty of instances where I use sc_field_display in onInit and it works fine.

I would still suggest you debug the generated PHP to find out the actual reason, unless you are just happy that it is working.

Regards,
Scott.

Re: sc_field_display in a form

Hi Scott,

the generated code is not identical. Lock …:

Code in onScriptInit:



if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{ 
  $original_anzahlaeberechnung = $this->anzahlaeberechnung;
  $original_istberechnungabweichend = $this->istberechnungabweichend;
}
   
if ($_SESSION['user']['groupid'] < 3)
{ 
  $this->nmgp_cmp_hidden["anzahlaeberechnung"] = "on"; $this->NM_ajax_info['fieldDisplay']['anzahlaeberechnung'] = 'on';
  $this->nmgp_cmp_hidden["istberechnungabweichend"] = "on"; $this->NM_ajax_info['fieldDisplay']['istberechnungabweichend'] = 'on';
}
else
{ 
  $this->nmgp_cmp_hidden["anzahlaeberechnung"] = "off"; $this->NM_ajax_info['fieldDisplay']['anzahlaeberechnung'] = 'off';
  $this->nmgp_cmp_hidden["istberechnungabweichend"] = "off"; $this->NM_ajax_info['fieldDisplay']['istberechnungabweichend'] = 'off';
}

Code in onLoad:


if ($_SESSION['user']['groupid'] < 3)
{ 
  $this->nmgp_cmp_hidden["anzahlaeberechnung"] = "on"; $this->NM_ajax_info['fieldDisplay']['anzahlaeberechnung'] = 'on';
  $this->nmgp_cmp_hidden["istberechnungabweichend"] = "on"; $this->NM_ajax_info['fieldDisplay']['istberechnungabweichend'] = 'on';
}
else
{ 
  $this->nmgp_cmp_hidden["anzahlaeberechnung"] = "off"; $this->NM_ajax_info['fieldDisplay']['anzahlaeberechnung'] = 'off';
  $this->nmgp_cmp_hidden["istberechnungabweichend"] = "off"; $this->NM_ajax_info['fieldDisplay']['istberechnungabweichend'] = 'off';
}

if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{ 
  if (($original_anzahlaeberechnung != $this->anzahlaeberechnung || (isset($bFlagRead_anzahlaeberechnung) && $bFlagRead_anzahlaeberechnung))&& isset($this->nmgp_refresh_row))
  { 
    $this->NM_ajax_info['fldList']['anzahlaeberechnung' . $this->nmgp_refresh_row]['type']  = 'text';
    $this->NM_ajax_info['fldList']['anzahlaeberechnung' . $this->nmgp_refresh_row]['valList'] = array($this->anzahlaeberechnung);
    $this->NM_ajax_changed['anzahlaeberechnung'] = true;
  }
  if (($original_istberechnungabweichend != $this->istberechnungabweichend || (isset($bFlagRead_istberechnungabweichend) && $bFlagRead_istberechnungabweichend))&& isset($this->nmgp_refresh_row))
  { 
    $this->NM_ajax_info['fldList']['istberechnungabweichend' . $this->nmgp_refresh_row]['type']  = 'checkbox';
    $this->NM_ajax_info['fldList']['istberechnungabweichend' . $this->nmgp_refresh_row]['valList'] = array($this->istberechnungabweichend);
    $this->NM_ajax_changed['istberechnungabweichend'] = true;
  }
}


Re: sc_field_display in a form

I think the reason is that the onScriptInit event is only triggered when the form is first loaded. You can navigate or sets a new record, then the Scrip not initialized again, so onScriptInit not processed. Therefore, the code is in the OnLoad (always is when a data set loaded) event correctly placed. For a new record is almost the loading of a data set with an empty primary key.

Deutsch:
Ich denke, dass die Ursache darin liegt, das das onScriptInit Event nur ausgel?st wird wenn das Formular das erste Mal geladen wird. Navigiert man, oder Legt einen neuen Datensatz an, dann wird das Scrip nicht nochmals initialisiert, also onScriptInit nicht abgearbeitet. Daher ist der code im OnLoad (immer wenn eine Datensatz geladen wird) Event richtig plaziert. Aus eine neuer Datensatz ist quasi das Laden eines Datensatzes mit einem leeren primary key.

Re: sc_field_display in a form

Thats correct. Onload will always execute when you navigate. onScriptInit executes when the connection to the database is open, if im not wrong.

Re: sc_field_display in a form

Thats correct. Onload will always execute when you navigate. onScriptInit executes when the connection to the database is open, if im not wrong.

That is a bit misleading… I would have guess that is what onApplicationInit was created for.
OnConnect, onAppInit would be a single instance, where onScript is when you call the app… before the fields are populated, onLoad for access to the populated fields.

Why would I want to re-load the form, create the fields, populate the fields… just to tell my app that I want to hide that field based on a session var.

Now it is known I guess.

Regards,
Scott.

Re: sc_field_display in a form

i’ll try to find more, but i think that onApplicationInit only execute once and it is before the database connection and the onScriptInit is after the database is open. But anyway i’ll try to figure out and i’ll post later.