Good morning pstevens,
Thanks for your help. I now understand the problem and was able to implement the new relationship.
For the already existing relationships I wrote a small help script which writes the missing values into the database. This works perfectly. In case someone stumbles over the same or a similar problem - you’ll find the script below.
Only one problem remains
If I want to add a new bug in the bug-subpanel of the account viewpage, the field where I have to select the account appears now. BUT: Since the account is already clear, I want the field to be prefilled with the name of the account. This doesn’t sound difficult, but I just can’t get it to work. Can you maybe point me in the right direction?
if(!defined('sugarEntry')) define('sugarEntry', true);
require_once 'include/entryPoint.php';
echo "<pre>";
$countBugs = 0;
$countUpdates = 0;
$countDryRun = 0;
$bugBean = BeanFactory::getBean('Bugs');
$allBugs = $bugBean->get_full_list();
// Iterate through all bugs
foreach ($allBugs as $bug) {
// only enter if the row is not updates yet!
if (!$bug->account_id_c) {
// if relationship is loaded
if ($bug->load_relationship('accounts'))
{
$accounts = $bug->accounts->getBeans();
foreach ($accounts as $account) {
//$bug->account_id_c = $account_id;
if ($_REQUEST['save']=='yes') {
$bug->account_id_c = $account->id;
$bug->save();
echo "UPDATED - ";
$countUpdates++;
}
else {
echo "TEST RUN - ";
$countDryRun++;
}
echo "Bug ID - " . $bug->id . " Account ID: " . $account->id . " Name: " . $account->name . "<br>";
}
}
}
$countBugs++;
}
echo "<br> Updates: " . $countUpdates;
echo "<br> Bugs: " . $countBugs;
echo "<br> Not updated: " . $countDryRun;
echo "<br>END";