Run button insert multiple record from 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:
[selected] = array();

GRID APPLICATION Run Button onRecord:
[selected][] = {RecordID};

The same Run Button onFISNISH:
if(count([selected]) > 0)
{
$to_copy = “(”.implode(’,’,[selected]).")";

sc_exec_sql("INSERT INTO Table2 (COL1, COL2, COL3) SELECT A, B, C FROM Table1 WHERE RecordID IN ".$to_copy);

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

Thanks,

I think you can convert an array into json object first…
I will give you an example how to parse a json object then catch variables then insert into table.
Below are my full code parse from url that contain json

$curl=curl_init();
curl_setopt_array($curl,array(
CURLOPT_URL => “http://…json url”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “GET”,

));
$response=curl_exec($curl);
$err=curl_error($curl);
curl_close($curl);
if($err)
{echo 'cURL Error #: '.$err;}
else

{

$resultarr = json_decode($response, true);
$tanggal=$resultarr[‘data’][‘0’][‘tanggal’];
sc_lookup(tgl1,“SELECT CURRENT_DATE”);
$tanggal1={tgl1[0][0]};

sc_exec_sql(“delete from your table”);
//POPULATE RESULT
$FINALRESULT = $resultarr[‘data’];

$all_values = [];
$query = "INSERT INTO your table (idne,kelurahan,odr,otg,odp,odpdp,odpsp,odpm,pdp,pdpdp,pdpsp,pdpm,p,ps,pm,pd,pi,tanggal,created_at) VALUES ";

foreach($FINALRESULT as $key) {
$row_values = [];
foreach($key as $s_key => $s_value) {
$row_values[] = “’”.$s_value."’";
}
$all_values[] = ‘(’.implode(’,’, $row_values).’)’;
}

//Implode all rows
$query .= implode(’,’, $all_values);
//$sql1=“select replace($query,’”’,’’’";

$query=str_replace("’’","‘0’",$query);
//$query=str_replace(’’’’,"‘0’",$query);
//echo $query;
sc_exec_sql($query);

}

sc_redir(http://…);

Oh ya above sql I am using postgres as my database

HI Suyonob,
Appreciated your supper prompt response, However this is something new to me. I haven’t tried Json before. I will try as you posted and keep you update in the forum.

Best,

Take this solution: