add5 - Data Area [message #7317] |
Wed, 17 July 2019 06:59 |
htManager
Messages: 433 Registered: May 2014
|
Senior Member |
|
|
Hi Tony,
I want to use an add5 pattern to insert multiple records into a table. I read in your documentation that I have to generate these records in the _cm_getInitialDataMultiple function. I wanted to see how you did this but I couldn't find the code in the prototype applications.
Can you please tell me where I can find this code?
Best regards,
Juergen
|
|
|
Re: add5 - Data Area [message #7318 is a reply to message #7317] |
Thu, 18 July 2019 05:29 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
There is no sample code for every pattern in the prototype applications as the circumstances which merit their use simply do not exist. You should be aware that the _cm_getInitialDataMultiple() method is only called once when the task is started and before the screen is displayed. It has one input argument called $fieldarray which initially contains any foreign key data which links it to the parent entity. This is also used as the output argument, so what you need to do is replace $fieldarray with a collection of as many rows as you like with whatever data you like.
function _cm_getInitialDataMultiple ($fieldarray)
{
$parent_data = $fieldarray;
$fieldarray = array(); // clear current data
while (...)
// create initial data for first row
$row = $this->_cm_getInitialData($parent_data);
$row['field1'] = 'whatever';
$row['field2'] = 'whatever';
$fieldarray[] = $row;
} // while
return $fieldarray;
} // _cm_getInitialDataMultiple
How many rows you create in $fieldarray is entirely up to you. It may be a fixed number, or it may depend on the contents of another table.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
|
Re: add5 - Data Area [message #7323 is a reply to message #7322] |
Sat, 20 July 2019 04:14 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You do not create several rows in the screen and then select which ones you wish to add to the database - all available rows which are not marked as deleted will be added. If you wish to add more rows than were initially created in the _cm_getInitialDataMultiple() method, or remove rows that you do not actually wish to add, then FAQ 156 is indeed the answer.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
|