If this is down to timing that the relationship doesn’t exist until the record is saved, then maybe I should use a before_save logic hook?
Having read a number of similar past posts on the issue, here’s what I’ve come up with:
logic_hooks.php in ./custom/modules/custm_submission
<?php
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(77, 'updateAccountsRelatedName', 'custom/Extension/modules/custm_submission/Ext/LogicHooks/updateAccountsRelatedName.php','updateAccountsRelatedName', 'main');
?>
updateAccountsRelatedName.php in ./custom/Extension/modules/custm_submission/Ext/LogicHooks
<?php
if (!defined('sugarEntry') || !sugarEntry)
die('Not A Valid Entry Point');
class updateAccountsRelatedName {
function main(&$bean, $event, $arguments) {
if ($bean->load_relationship('custm_submission_accounts')) {
//Fetch related beans
$relatedBeans = $bean->custm_submission_accounts->getBeans();
$relatedBeans = reset($relatedBeans);
$realaccountname = $relatedBeans->name;
}
$bean->custm_submission_accounts_name = $realaccountname;
}
}?>
Does the above sound roughly like the steps you had taken?
Or are there any notable differences?
It might be worth running a “Quick Repair and Rebuild” and a “Rebuild Relationships”, in case anything needs to be cleaned up from creating the Custom Module
(Both found in Admin->Repair)
Also, it would be good to get some more information, perhaps there are some obvious differences in environment or something?
Which SuiteCRM Version are you using? (I’m on 7.11.18)
Which PHP version are you on? (I’m on 7.3)
Did you create the relationships from Custom Module -> Invoices/Accounts before or after deploying? (ie, in module builder or studio)
Ultimately, if a Workflow does end up being unsuitable, a Logic Hook most definitely would work
(As you have much more freedom at a code-level than you do in Workflow)
Thanks for your time looking into this. The steps we’ve both taken look identical.
The difference I can see from your screenshot is that you have the Accounts relationship field already populated before save. Have you manually done that?
The new custom module record is created from the subpanel on the Account and I don’t have that relationship populated until after the save.
Apologies if all this is “obvious” or “by design”…very new to SuiteCRM.
Incidentally, I set the Account manually before save and I see the same behaviour. Custom module record saves the Accounts relationship, Invoices doesn’t.
Using SuiteCRM version 7.11.18,
PHP 7.4 <- do you think this is the root of the issue? Had advice to downgrade to 7.3 in other support posts just not done it yet,
Created the relationships from Custom Module before deploying…I think. Memory a bit sketchy on the precise detail. May have added Accounts relationship in the custom module before deploying, then deploying, then added the Invoices relationship in the custom module, then redeploying.
Ahhh right, I was creating the record from the full-form Editview of the Custom Module, and manually selecting the “Account” record
However, If I do it from the Accounts->Custom Module subpanel, I get the same issue as yourself
I think you’re probably right, it seems to simply be due to the order of the relationships being added
Your best option might indeed be a logic hook
From a logic hook, you should be able to create an Invoice record, and relate it to both the Account & Custom Module record
I’ve been playing around with it, and the following will create an Invoice & relate the correct Account
But I haven’t yet been able to relate the Invoice to the Custom Module record: