Run button insert multiple record from search fields in Grid application

I have created virtual field in Grid and I’m displaying some values in that field.

The below code is working but I want to include the value of grid virtual field along with insert statement. Please advise.

OnScriptInit:
[i] = 0;
[selected] = array();
[vDeducted_StartDate]={Deducted_StartDate};
[vDeducted_EndDate]={Deducted_EndDate};

GRID APPLICATION Run Button onRecord:
$arr=[i];
[selected][$arr]={EmployeeNo};
[i]++;

$Deducted_StartDate = [Deducted_StartDate];
$Deducted_EndDate = [Deducted_EndDate];

if(count([selected]) > 0)
{
$to_copy = implode(’,’,[selected]);
$sql = “INSERT INTO Food_BonDeduction (EmployeeNo, Deducted, Deducted_StartDate, Deducted_EndDate, Accommodat_Emp_IDF) SELECT EmployeeNo, ‘نعم’,’$Deducted_StartDate’, ‘$Deducted_EndDate’, Accommodat_Emp_ID FROM view_newaccommodates WHERE EmployeeNo =’$to_copy’”;
sc_exec_sql($sql);
[selected] = array();
}

========
when working in developping mode it show this window and insert data into Food_BonDeduction table very good
image

but when working in production mode it does not show any window and insert Deducted_StartDate= 0000-00-00, Deducted_EndDateinto=0000-00-00 into Food_BonDeduction table


Please advise how to add insert value to Food_BonDeduction FROM Grid application virtual field.

Thanks,

in production mode SC does not ask for your parameters.
In this case you must create a control app for ask for your dates. and then call to your grid.

I am very thanks for your response
But I do not know how that
Can you please help me in steps

Is it possible to passing variable in a message

in your new app control, event onvalidate, you can send your variables with this macro:
sc_redir(application_x, parm1={var_test}; parm2=“xxx”);

ex:
sc_redir(add_FoodDeduction_Multi_accommodate, vDeducted_StartDate={Deducted_StartDate}; vDeducted_EndDate={Deducted_EndDate});

1 Like

I will always remember how you helped me to solve these complexed issues. I can only hope that someday I’ll be in a position to repay you.
I will try tomorrow in the morning.

I try many times but I failed.
1- I made the control app. like this Photo


2- Then I modified the grid app. like this photo

although it did not work till now

Please help me to solve this issue

Thanks for God … I try many times, So now it working very Good
If anyone deserves thanks, it’s you.
:blossom:
I really appreciate your support in this endeavor.

Hi, how are you. today i can help you: (if get an error )
You have bad your code, You must change the variable:
app control:
sc_redir(add_FoodDeduction_Multi_accommodate, vDeducted_StartDate={vDeducted_StartDate}; vDeducted_EndDate={vDeducted_EndDate});

and

Grid: On Record Button
$vDeducted_StartDate = [vDeducted_StartDate];
$vDeducted_EndDate = [vDeducted_EndDate];

2 Likes

Dear Alvagar,
I will always remember how you helped me to solve these complexed issues. I can only hope that someday I’ll be in a position to repay you.

1 Like

Hi, Eissa,
I Hope your form work fine.
:wink:

1 Like

Is there a way to fill in the date field completely through the variables $vDeducted_StartDate and $vDeducted_EndDate, so that there are no of records with the number of days of the month one time using loop
Thank you very much in advance

Hi, i don´t undestand your question?

1 Like

First of all, Many thanks for your response.
You know that I have control Application that reserve 2 dates $vDeducted_StartDate and $vDeducted_EndDate,
After that I insert the value of these variables into a grid application, So Every employee has one record.
My question is how i make a loop into a code to insert 30 record for every employee instead of 1 record

hi, you can do a loop like this:

{amount_days} = sc_date_dif($vDeducted_EndDate, “aaaa-mm-dd”, $vDeducted_StartDate , “aaaa-mm-dd”);

// the loop

for ($v_day = 0; $v_day <= {amount_days}; $v_day++) {

// your insert clause: insert into mytable(field_date) values (DATE_ADD ($vDeducted_StartDate,INTERVAL $v_day DAY) )
}

1 Like

I get this error

first: the control App

Second: the grid App

The result that the field Recieved_Date is empty
So, Please If possible can you check my code and correct any errors
Thanks in advance

I change the code like this:
$arr=[i];
[selected][$arr]={Accommodat_Emp_ID};
[i]++;

$vRecieved_StartDate = [vRecieved_StartDate];
$vRecieved_EndDate = [vRecieved_EndDate];

//[var_Recieved_StartDate] = {vRecieved_StartDate};//[var_Recieved_EndDate] = {vRecieved_EndDate};
// first , last and current day of current: last_day(curdate() - interval 1 month) + interval 1 day // last_day(curdate()) // curdate()
{amount_days} = sc_date_dif($vRecieved_StartDate, “aaaa-mm-dd”, $vRecieved_EndDate , “aaaa-mm-dd”);
// the loop
for ($v_day = 0; $v_day <= {amount_days}; $v_day++) {

if(count([selected]) > 0)
{
$to_copy = implode(’,’,[selected]); //"(".implode(’,’,[selected]).")"; curdate()

$sql = “INSERT IGNORE INTO Food_BonRecieveSent (EmployeeNo, Accommodat_Emp_IDF, Recieved, Recieved_Date) SELECT EmployeeNo, Accommodat_Emp_ID, ‘نعم’, DATE_ADD ($vRecieved_StartDate,INTERVAL $v_day DAY) FROM view_newaccommodates WHERE Accommodat_Emp_ID =’$to_copy’”;
//$sql = “INSERT INTO Food_BonRecieveSent (EmployeeNo, Accommodat_Emp_IDF, Recieved, Recieved_Date) SELECT EmployeeNo, Accommodat_Emp_ID, ‘نعم’,curdate() FROM emp_accommodate WHERE EmployeeNo =’$to_copy’”;
sc_exec_sql($sql);

//sc_error_exit();
//$sql_Update = “UPDATE Emp_Accommodate SET EmployeeNo = ‘’ WHERE EmployeeNo= {EmployeeNo}”;
//sc_exec_sql($sql_Update);
[selected] = array();
}
}
But no way result
Please can you help me

Hi,
You can do a trace for know for error.
Change variable {amount_days} by $amount_days
and set echos for your variables so you can know where can be the errors:
echo $amount_days;
echo (count([selected]);

1 Like

Many thanks for your response