Basing records in many forms based on one grid record

Hi,

A bit of a complicated on to describe but I have a feeling my logic is good but my knowledge not!

I have an application were the users logs in and picks a client (on a button press), once the client is picked, this calls a tab application, which has about 10 tabs, all with information relating to the client picked. My guess would be to in some way, when the client is picked, set a session or global variable and then use that in the where clause on each of the forms or grids in each of the tabs. If this is the correct way to do it, I can’t work out how to set the session or global variable on picking the client. If this isn’t the way, I’d be interested to hear what is.

Any help would be very appreciated.

Regards,

Mike

Re: Basing records in many forms based on one grid record

This can depend on your approach.

How are you calling the client detail form on select? Using a SC link, or sc_link, or sc_redir()???

If you are sending a variable to the form, then you can use PHP to {id_client} = $_GET[‘url_id’] or you can use SC to capture the ‘id’ in your where statement: id = [url_id]
If you want to use a session:

In login form:
$_SESSION[‘client’][‘id’] = {id_client}

In detail form: oninit
if (isset($_SESSION[‘client’][‘id’])) {
{id_client} = $_SESSION[‘client’][‘id’];
}

Regards,
Scott.

Re: Basing records in many forms based on one grid record

Hi Scott,

Thanks so much for the reply.

Unfortunately my knowledge is very limited, I’ve probably done 10-15 hours of work on Scriptcase and this was mostly mockups for a client, now I am trying to put the bones onto it. I would guess it is an SC link, as what I did was create a field of type HTML image, then I linked in the tab application using the linking capability.

I also probably should have been clearer and not put in things that are actually irrelevant. That the user logs in is irrelevant. The relevant part is a grid of clients

which has HTML image as the last column, which when pressed links to the tab application. Actually, let me give you the link on the image

javascript:nm_gp_submit5(’/scriptcase/app/app/client_tabs/client_tabs.php’,%20’/scriptcase/app/app/grid_clients/grid_clients.php’,%20’nmgp_lig_edit_lapis?#?S?@?id?#?1?@?’,%20’_self’,%20’inicio’,%20’0’,%20’0’)

it may give you clues as to what I am doing, as I’m not sure now :slight_smile:

When clicked it then looks like this

Regards,

Mike

Re: Basing records in many forms based on one grid record

You could most likely assign a global var in SC and then use that global in each app assigned to the tab in either the where condition of the SQL of the app.

Several notes:

I created a global in onLoad of my Login App. [crazy_global] = sc_macro to create a session array.

What SC does is simply create a session var for this global as seen in the generated code:


   if (isset($this->crazy_global) && isset($this->NM_contr_var_session) && $this->NM_contr_var_session == "Yes") 
   {
     $_SESSION['crazy_global'] = $this->crazy_global;
   }
   if (isset($_POST["crazy_global"])) 
   {
     $_SESSION['crazy_global'] = $this->crazy_global;
   }
   if (isset($_GET["crazy_global"])) 
   {
     $_SESSION['crazy_global'] = $this->crazy_global;
   }

That is a lot of extra code to declare a session var :wink:

You can use this approach, or create your own multi-dim session array if you plan to have more info available to your project across apps and use a local var to access the array
$_SESSION[‘client’][id’];
$_SESSION[‘client’][‘name’];
$my_client_array = $_SESSION[‘client’];

If you just need the client id, then this is overkill, but if you want to structure your session data, then you can run into headaches trying to manage all your sc global array vars especially if you want to access an array element in PHP or JS and SC is trying to declare an element as a global because you have it inside [] where you have to remember to put spaces
my_array[0][ i ].

The [] were not a good delimiter choice IMO.

Regards,
Scott.

Re: Basing records in many forms based on one grid record

Hi Scott,

Thanks for that, some good pointers there. The thing I don’t get is how do I get the value for the record clicked in the clients grid into this (any) variable, so I can use it in other forms/grids?

Regards,

Mike

Re: Basing records in many forms based on one grid record

I usually create manual link using sc_link in my grid using the onRecord event. It creates a link on the field I choose using sc_link. sc_link also allows you to create a global (session) var and it can be access from called app

onRecord:
sc_link(user_name, form_edit_users.php, id_user={id_user}, , “_self”);

This creates a link on field user_name and creates a global called id_user. In the called app, you can then access it using [id_user].
Same thing when you created the html field and setup the link. The field you assign will be global that you access from the called app [html_link_field_assgined]

Another thing you can do is click on the link on your grid, then jump over to SC and click View/Data in Session … and it will display all the variables available. Find the value and it will have the name of the field you need.

Regards,
Scott.

Re: Basing records in many forms based on one grid record

Hi Scott,

All your tips and pointers gave me the, well pointers and impetus to get this done!! The fix was as follows

In the grid form I kept my link, that was passing a parameter (id) to another program, the tab application.

In the tab application I changed the global variable id, to be session as well as post and get.

In the other forms and grids in the app, I then put in the where clause

where client_id=[id]

Finally, in the attribute values of the form settings, for client ID (the foreign key to the client table) I set it to be a Defined value and value of [id]. So when I insert, the correct client ID is put in the linking field.

Thanks so much for the help. I do have another issue but I am going to try to work through this one myself :slight_smile: … but you may hear from me again :wink:

Regards,

Mike

Re: Basing records in many forms based on one grid record

Glad you got it working … and thanks for posting the solution.

Regards,
Scott.