Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By michalborkowski
#790473
Hi,
I need some help with understanding how to merge data from two grids into 3rd one.
Both Grids have unique ID like: Grid1, Grid2 and they have the same field Id's like: Partner, Details, Cost

Dynaform1
Grid1

Dynaform2
Grid2

Summary
Dynaform3
Grid 3 (data from Grid1 and Grid2)

I can't merge the data... I've tried to:
- populate the grid using database query (from wiki) -> It is not possible to execute the query. Please contact your system administrator
- use the modified method described in viewtopic.php?f=44&t=709866&p=788407&hi ... ds#p788407 to merge the data but I can't merge the data, I can only put the data from Grid1 or Grid2.

Thanks for help,
Michal
By mishika
#790475
Hello,

To merge data of two grids into a single grid you need to write the following trigger code:
Code: Select all
if (isset(@=gridVar001) and is_array(@=gridVar001)) {
   for ($i = 1; $i <= count(@=gridVar001); $i++) {
      @=gridVar003[$i] = @=gridVar001[$i];
      }
   }
if (isset(@=gridVar002) and is_array(@=gridVar002)) {
	$count = count(@=gridVar001) + 1;
   for ($i = 1,$j = $count; $i <= count(@=gridVar002); $i++,$j++) {
      @=gridVar003[$j] = @=gridVar002[$i];
      }
   }
where gridVar001 is ID for first grid, gridVar002 is the ID for second grid and gridVar003 is ID for the grid which will store the combined data from two grids.
Make sure that the structure of all the three grids is the same.
Place this trigger Before the Dynaform containing the third grid.

You can also refer the attached process, which has the three Dynaforms in three steps of a task and trigger placed before step 3.
(32.04 KiB) Downloaded 314 times
Hope this helps

Best Regards
Mishika
By michalborkowski
#790477
Mishika,

Thanks for the quick reply !
Trigger code works great :)
I have one more question for the merging method. What to do if I would like to merge more grids? 3 or 4 etc.

Regards,
Michal
By mishika
#790486
Hello Michal,

If you want to merge more than 2 grids, you need to further expand the trigger code for all of them.
Like for 4 grids, the code will look like:
Code: Select all
if (isset(@=gridVar001) and is_array(@=gridVar001)) {
   for ($i = 1; $i <= count(@=gridVar001); $i++) {
      @=gridVar003[$i] = @=gridVar001[$i];
      }
   }
if (isset(@=gridVar002) and is_array(@=gridVar002)) {
   $count = count(@=gridVar003) + 1;
   for ($i = 1,$j = $count; $i <= count(@=gridVar002); $i++,$j++) {
      @=gridVar003[$j] = @=gridVar002[$i];
      }
   }
if (isset(@=gridVar004) and is_array(@=gridVar004)) {
   $count = count(@=gridVar003) + 1;
   for ($i = 1,$j = $count; $i <= count(@=gridVar004); $i++,$j++) {
      @=gridVar003[$j] = @=gridVar004[$i];
      }
   }
if (isset(@=gridVar005) and is_array(@=gridVar005)) {
   $count = count(@=gridVar003) + 1;
   for ($i = 1,$j = $count; $i <= count(@=gridVar005); $i++,$j++) {
      @=gridVar003[$j] = @=gridVar005[$i];
      }
   }
Please note that here I have taken $count = count(@=gridVar003) instead of count(@=gridVar001), because the gridVar003 continues to add more rows to it.
This code will continue in the same way for more grids.

Hope this helps

Best Regards
Mishika
By michalborkowski
#790487
Mishika,
This is exactly what I did yesterday :) but there is one problem with this formula.
3 Grids -> copy to 4th Grid
If I enter for the for the first time to the Summary Task (trigger before dynaform), then exit, and enter again (again trigger before dynaform) then the duplicated values will show from the 3rd grid.
Should I add command to clear the 4th summary grid before filling it with the data?

Test process attached.
Attachments
(58.44 KiB) Downloaded 318 times
By mishika
#790490
Hello,

You are right. Duplicity happens in the trigger.
Yes, you can clear the grid before copying the grids to it.
You just need to add the line:
Code: Select all
@=gridVar003 = array();
in the beginning of the trigger and then continue with the same code.
@=gridVar003 is the summary grid.

Hope this helps

Best Regards
Mishika
User avatar
By erpnedir
#812382
You can also use PHP's array_merge() function.
The only problem is php starts the merged array with index 0. PM grids starts with index 1. This can be handled by inserting a manual row before merging.
Check my Test process attached.
Attachments
(28.42 KiB) Downloaded 382 times

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]