sc_redir with parameters...

Hello,
I got a grid with a htlm image button that call/open a Blank application . On the grid I got defined 3 global variables like that:

[glo_customer_id]={id_customer};
[glo_id_instrument]={id_instrument};
[glo_serial_numenr]={serial_number};

Within the blank I inserted a sc_redir macro to open a form trying to use the globals variable as default values for some form’s field.
these 3 form’s field are

{customerid}
{id_instrument}
{seriale}

sc_redir(form_ticket_insert, {customerid}=[glo_customer_id], {id_instrument}=[glo_id_instrument],{seriale}=[glo_serial_numenr]);

It doesn’t work … Probably I’ve not clear how parameters work.
Can somebody help me to fix it ?

You need a ; to seperate params and to the left of the = sign you shoudn’t use variables:

sc_redir(form_ticket_insert, customerid=[glo_customer_id];id_instrument=[glo_id_instrument];seriale=[glo_serial_numenr]);

But if you defined them as global variables, you don’ need to pass them as params.
In the form onLoad all you need shoud be this:

{id_customer} = [glo_customer_id];
{id_instrument} = [glo_id_instrument];
{serial_number} = [glo_serial_numenr];

To be sure those default values are not set when not intended, you should also add some extra lines before\after the three lines above.

Furthermore, does the blank app perform any operations other than the sc_redir?
If not, I don’t understand why you need a blank app to open the form from the grid.

thanks Roby for help…:wink: I use blank to send parameters but , as you said, using global is redundant…

The form has on board the macro sc_apl_conf(“form_ticket_insert”, “start”, “new”); on onApplicationInit.
If I use the form starting from menu --> the fields have to remain empty.

If I start from the grid , using html image button, I need to pre-fill some fields because I got all values available on grid’s row selected.

The two ways to populate the form are compatible or sc_apl_conf clean everytime all ?
Thanks

Not sure I understand what you’re doing and I never use sc_apl_conf so I have no experience with it.

If you need to set those default values only on new records and only when the global variables are set, one easy way should be to check if the primary id field of the form db table is empty and only then set the fields.

Form app onLoad event:

if (empty({id_of_the_table_primary_key_field}))
{
 if (!empty([glo_customer_id])) {  {id_customer} = [glo_customer_id]; }
 if (!empty([glo_id_instrument])) {  {id_instrument} = [glo_id_instrument]; }
 if (!empty([glo_serial_numenr])) {  {serial_number} = [glo_serial_numenr]; }
}
sc_reset_global ([glo_customer_id], [glo_id_instrument], [glo_serial_numenr]);

I’ve not written ested the above code in SC, so you have to check the syntax.
Also I’m not sure the check for empty of the global vars won’t throw an error if the form is loaded when the global vars are not set; in that case maybe empty() shoud be substituted by isset().

Great Roby , it makes sense. I will try for sure !!