Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Transaction Patterns » PopUp changes Key fields
PopUp changes Key fields [message #7158] Wed, 20 June 2018 03:04 Go to next message
htManager is currently offline  htManager
Messages: 434
Registered: May 2014
Senior Member
Hi Toni,

I have a detail screen (upd1) in which I can call a popup (popup1) to change the corresponding values of a foreign key. After PopUp-Return the key fields of the record are also changed. The first three fields in both tables have the same name.
The popup fills in the correct values but the following error message appears:

Could not locate original ORGA_MANNSCHAFTEN_KONTAKTE record for updating (verbaende_art_id='LV' AND verbaende_kuerzel='HV S' AND vereine_kuerzel='SCA' AND saison_id='2017/2018' AND mannschaften_id='2005W' AND kontakt_ma_user_id='HTM' AND kontakt_ma_user_seq_no='195' AND kontakt_ma_user_rdcaccount_id='7')

What did I wrong?

Best regards,

Juergen
Re: PopUp changes Key fields [message #7159 is a reply to message #7158] Wed, 20 June 2018 04:58 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
The popup is bringing back values which are to be used in a foreign key, so how is the relationship with that parent table defined?

You may wish to put code in the _cm_popupReturn() method in order to handle the insertion of these columns manually instead of relying on the default behaviour.


Re: PopUp changes Key fields [message #7160 is a reply to message #7159] Wed, 20 June 2018 05:13 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 434
Registered: May 2014
Senior Member
The relationships seems to be fine.

I put the following code in the _cm_PopUpReturn() function:

function _cm_popupReturn ($fieldarray, $return_from, &$select_array, $return_files)
{
// liest Daten in Abhängigkeit des aufrufenden Formulars ein
switch ($return_from) {
case 'htm_orga_vereine(popup1)' :

// get contents of foreign table ORGA_VEREINE
$dbobject =& RDCsingleton::getInstance('orga_vereine'); // Instanz für Lookup-Tabelle
$where = "verbaende_art_id='{$select_array['verbaende_art_id']}'
AND verbaende_kuerzel='{$select_array['verbaende_kuerzel']}'
AND vereine_kuerzel='{$select_array['vereine_kuerzel']}'";

$data = $dbobject->getData ($where);

if (!empty($data)){
$data = $data[0];

$fieldarray['kontakt_stamm_verbaende_art_id'] = $data['verbaende_art_id'];
$fieldarray['kontakt_stamm_verbaende_kuerzel'] = $data['verbaende_kuerzel'];
$fieldarray['kontakt_stamm_vereine_kuerzel'] = $data['vereine_kuerzel'];

$fieldarray['kontakt_stamm_vereine_name'] = $data['vereine_name'];
} // if
else
{
$fieldarray['kontakt_stamm_vereine_name'] = '';
}
// else

} // switch

return $fieldarray;

}

The key values for verbaende_art_id, verbaende_kuerzel and vereine_kuerzel are changed as well.
Re: PopUp changes Key fields [message #7161 is a reply to message #7160] Thu, 21 June 2018 04:42 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
Can you provide a copy of your dict.inc file so that I can see your relationship details and the fieldspecs for the affected columns?

If the popup is returning columns with the names 'verbaende_art_id', 'verbaende_kuerzel' and 'vereine_kuerzel' then these columns will be copied across to your $fieldarray. If the column names in your $fieldarray are different then you need to delete the contents of $select_array after you have copied them to $fieldarray.


Re: PopUp changes Key fields [message #7162 is a reply to message #7161] Fri, 22 June 2018 03:41 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 434
Registered: May 2014
Senior Member
Yes, that works. Before getting the additional data I copy the values in verbaende_art_id_old, verbaende_kuerzel_old... and later I copy these values in the $select_array.

// liest Schluessel-Werte ein
$verbaende_art_id_old = $fieldarray['verbaende_art_id'];
$verbaende_kuerzel_old = $fieldarray['verbaende_kuerzel'];
$vereine_kuerzel_old = $fieldarray['vereine_kuerzel'];

// get contents of foreign table ORGA_VEREINE
$dbobject =& RDCsingleton::getInstance('orga_vereine'); // Instanz für Lookup-Tabelle
$where = "verbaende_art_id='{$select_array['verbaende_art_id']}'
AND verbaende_kuerzel='{$select_array['verbaende_kuerzel']}'
AND vereine_kuerzel='{$select_array['vereine_kuerzel']}'";

$data = $dbobject->getData ($where);

if (!empty($data)){
$data = $data[0];

$fieldarray['kontakt_stamm_verbaende_art_id'] = $data['verbaende_art_id'];
$fieldarray['kontakt_stamm_verbaende_kuerzel'] = $data['verbaende_kuerzel'];
$fieldarray['kontakt_stamm_vereine_kuerzel'] = $data['vereine_kuerzel'];

$fieldarray['kontakt_stamm_vereine_name'] = $data['vereine_name'];

$select_array['verbaende_art_id'] = $verbaende_art_id_old;
$select_array['verbaende_kuerzel'] = $verbaende_kuerzel_old;
$select_array['vereine_kuerzel'] = $vereine_kuerzel_old;

I don't know exactly but I think that this worked earlier. Did you change something in the latest versions?
Re: PopUp changes Key fields [message #7163 is a reply to message #7162] Fri, 22 June 2018 05:05 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
What is the relationship between 'kontakt_stamm_verbaende_art_id' and 'verbaende_art_id'?
Which is returned from the popup form and which is saved in your $fieldarray?
Which do you NOT want stored in your $fieldarray?

If you want the value for 'verbaende_art_id' stored as 'kontakt_stamm_verbaende_art_id' and not 'verbaende_art_id' then you must remove it from $select_array before you exist from _cm_popupReturn().


Re: PopUp changes Key fields [message #7164 is a reply to message #7163] Fri, 22 June 2018 09:36 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 434
Registered: May 2014
Senior Member
I attached the orga_mannschaften_kontakte.dict.inc so you can see the fields.

The fields 'kontakt_stamm_verbaende_art_id', 'kontakt_stamm_verbaende_kuerzel', 'kontakt_stamm_vereine_kuerzel' relate to table 'orga_vereine' where the logo is saved which I want to display. The key fields begin in almost all tables with these fields. So I have the possibility for relationships.

$field_array in _cm_PopUpReturn has the correct key values
$select_array has the key values of the chosen record in the popup form

But you can see that in the screen the key values are changed from $field_array values to $select_array values.
Re: PopUp changes Key fields [message #7165 is a reply to message #7164] Sat, 23 June 2018 04:28 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
There is no screen shot, so I cannot see anything. You have given me the dict file for table 'orga_mannschaften_kontakte' and say that the popup data is being provided from table 'orga_vereine', but I cannot see any relationship between these two tables.

The whole purpose of a popup is to provide values from a record which you have selected from another table, and these values are provided in $select_array. By default these values will be copied into $fieldarray, thus overwriting those fields with the same names. If you don't want any values to be overwritten then you must remove them from $select_array before you exit from _cm_popupReturn().


Re: PopUp changes Key fields [message #7166 is a reply to message #7165] Sun, 24 June 2018 11:52 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 434
Registered: May 2014
Senior Member
I attached a file with two screenshots. On the left hand you can see the record before calling the PopUp and on the right hand you see the record after PopUpReturn.

The corresponding relationship in the dict.inc file is:

$this->parent_relations[] = array('parent' => 'orga_vereine',
'parent_field' => 'vereine_name',
'fields' => array('kontakt_stamm_verbaende_art_id' => 'verbaende_art_id',
'kontakt_stamm_verbaende_kuerzel' => 'verbaende_kuerzel',
'kontakt_stamm_vereine_kuerzel' => 'vereine_kuerzel'));

You say that the values in $select_array will be copied in $fieldarray by default. Is it possible that the key field values from the PopUp table 'orga_vereine' are additionally copied to the key field values of 'orga_mannschaften_kontakte' because they both have the same names?
  • Attachment: PopUp.jpg
    (Size: 137.86KB, Downloaded 1068 times)
Re: PopUp changes Key fields [message #7167 is a reply to message #7166] Mon, 25 June 2018 04:34 Go to previous message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
There is no reference to table 'orga_vereine' in the dict.inc file which you provided.

$fieldarray and $select_array are both associative arrays, and the default behaviour is to copy the contents of $select_array into $fieldarray. However, instead of using a simple array_merge() there is code in the popupReturn() method of std.table.class.inc that uses the field mapping in the $parent_relations entry to copy from $fld_parent to $fld_$child. If this field mapping is causing a problem then you need code in your _cm_popupReturn() method to move values from $select_array to $fieldarray using the names that you want, then you erase the contents of $select_array.


Previous Topic: VPD - PopUp
Next Topic: IDE Validation Issues
Goto Forum:
  


Current Time: Sat Nov 23 22:20:49 EST 2024

Total time taken to generate the page: 0.40483 seconds