What is the subquery to assigned user id in child object same as parents object through logic hooks?
What is the subquery to assigned user id in child object same as parents object through logic hooks?
Here is a tiny Logic Builder flowchart that configures that logic hook for Contacts-belong-to-Account relationship (control flow is a white line)
Zip generated is also attached below -just install it with Module Loader
and zip file:
Best Regards,
Dmytro Chupylka
integroscrm.com
We make work in Sugar CRM system faster, more convenient and efficient
If I understand correctly, when on a given record you change the assigned user, you want to update all related records to have the same assigned user.
The tricky part will be finding all the related records unless you list them explicitly in your logic hook.
If you don't want to hardcode which children are reassigned you may have to iterate through all the "link" fields as suggested by Angel Magana here:
Once you know the names of each link you can load the relationship between the $bean (your parent) and the linked module via the $link
if($bean->load_relationship($link)){ //check the relationship exists foreach($bean->$link->getBeans() as $linkedBean){ //get the linked bean $linkedBean->assigned_user_id = $bean->assigned_user_id; //change the assigned user $linkedBean->save(); //save the linked bean } }
You may need to check the teams as well to make sure they are consistent with the new assignment.
FrancescaS
I have created a building object and in Building object i have created Flat object . I have assigned a building to "km". my question is how to write logichooks through after_relationship_add , all flats of building assigned to same name km.
There is a much easier way for Sugar Admins for setting up logic hooks and configuring algorithms for the SugarCRM platform, than upgrading skills to PHP coding and learning to create correct enhancement packages - a lot of typical tasks are configurable no-code with a Logic Builder tool.
For example, if buildings are represented as x_Building module and flats are represented as x_Flat module with 1:m relationship from Buildings to Flats, the drawing is simple:
And zip generated by Logic Builder with a click is:
z20220208_flowchart_lb62022a9ac5dec5_41227977.zip
In case of modules' names are different from x_Building and x_Flat or the relationship is different from 1:m, it takes a few minutes to switch to that module names in the example and generate the new logic hook to deploy with regular Module Loader.
What are the names of your modules as they are shown in the URL?
I hope this helps
Best Regards,
Dmytro Chupylka
integroscrm.com
We make work in Sugar CRM system faster, more convenient and efficient
What Dmytro is proposing to you is to sell you a third party visual tool that builds the code of the logic hook for you. If you are not keen on coding that may be a solution for you.
So, let's assume that you are looking for a code solution, which in this case is not hard to do.
the trick with after_relationship_add logic hooks is that they provide you all the information for both the current bean (the record you are on when the the hook is triggered) and the related bean (the record to which you are relating your current record)
As you can see here:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_11.0/Architecture/Logic_Hooks/Module_Hooks/after_relationship_add/
the related_module will tell you what type of record you are relating the current record to
and the related_id will tell you the ID of that record.
This means you can use the BeanFactory
to get the full bean, which will contain the information you need: the assigned_user_id, and use it to assign the Flat to the correct user.
In your logic hooks on the Flat module, in the after_relationship_add you can do as follows:
function flatAssignedUser($bean, $event, $arguments){ //check if the Flat was just related to a Building by checking the related module name if($arguments['related_module'] == 'Buildings'){ //get the Building information $buildingBean = BeanFactory::retireveBean('Buildings', $arguments['related_id']); //double check that you have a building bean if(!empty($buildingBean)){ //copy the assigned user from the buildingBean to the bean (the Flat) and save $bean->assigned_user_id = $buildingBean->assigned_user_id; $bean->save(); } } }
I hope you find this helpful.
FrancescaS
Even better! Look at André Lopes's answer here, it is a MUCH cleaner solution than logic hooks.
FrancescaS
thanks, good to know that could be done so easily with parent module code adjustments!
I wonder whether using "case" filed is a misprint in the custom code example there...
Anyway it should be definitely easy to write it for those who keen on Sugar code development
Best Regards,
Dmytro Chupylka
integroscrm.com
We make work in Sugar CRM system faster, more convenient and efficient
Francesca Shiekh, it seems this should be cleared out - I'm helping to solve the particular business challenge via configuring a logic hook with no-code tools I have unlimited access to.
It takes minutes for me to help and I don't ask anything in return except maybe to give a note on whether the configuration performed solves the case.
For the Clubmates, who are not certified Sugar Developers, the no-code approach allows receiving a result without diving into the SDLC cycle with performing adjustments to the out-of-the-box Sugar code - literally, mitigate the risks of amateur coding consequences.
No-code tools are very handy and that is why modern CRMs do the best to include them - there are no-code tools Studio and Sugar BPM in modern SugarCRM
Again, I'm absolutely not the only one who benefits from the no-code configuring approach, e.g.
https://sugarclub.sugarcrm.com/explore/enterprise-professional/f/enterprise-professional-questions/5302/webinar---how-to-sync-client-data-via-aws-api-gateway-without-php-knowledge
or
https://sugarclub.sugarcrm.com/engage/b/partner-stories/posts/how-analysts-can-do-more-for-customers-and-their-own-company
I hope this shows that being keen on solving specific CRM tasks with Sugar does not automatically mean being keen on coding for open source.
Best Regards,
Dmytro Chupylka
integroscrm.com
We make work in Sugar CRM system faster, more convenient and efficient