I have form and want save logged current username by adding new record into field “CreatedBy” in the database.
If you have a global variable containing the current username i.e. [glob_username] then you can go to to edit fields, go to the CreatedByField and set the default [glob_user] to the insert value. Check the forced value field.
Thanks your reply, I’m new to Scriptcase.
How can I create global variable containing the current username?
Welcome mokenned,
Most of us here are fellow SC users. SC is pretty cool to use. The global vars are very easy.
Essentially anything with brackets around it is a global var - you can use them in your PHP code in the events of any app.
[glo_dog] = “this get stored in the global variable as a string”;
[glo_cat] = 1.257;
You can also use the SC macro in your events to set globals as well. Help is onlinne: http://www.scriptcase.net/docs/en_us/manual_mp.htm#scriptcase-macros/scriptcase-macros
example of a macro from the help:
$my_var = “mary”;
sc_set_global($my_var);
When you make a global var you can call it anything you want, but I usually make it have glo_ or something easy for me to spot months later when debugging.
Another concept in SC is that globals can be coming in or going out of an app. If you look under application, global variables - you will see every global you have used in your event code. It goes in there automatically, as soon as you save code in any event. However, you usually have to specify which direction it is coming. I usually check SESSION and OUT, if I created the global in teh current app and will be using it in another app, like passing the second app a value it will need to process something. If the global is only being used in an app, as if it is coming from outside the app, check IN.
You can do other things with globals, like using them in the settings of an app. Like putting a [glo_this_title] into the layout’s title setting, then use an event like OnScriptInit or something to set the value based on your PHP code. You have to look at which events get triggered when (sometimes a tricky thing), but it works great. Globals are also involved in GET and PUT type parameter passing too - but you will have to look that up in the help and this forum.
Good luck my friend,
Jamie
PS There is also a viewer built into SC that lets you see the global variables in the session while you are developing things. If you have used SC to create your security apps, they already set some things for you that you can reuse in other apps… explore around the login app events and see what is there.