Hello, I created a field type ārelateā. I called the field āagente_cā and I connected to the users module. There would be a way to auto fill this field with the name of the connected user? I would like to make it work how the field āAssigned toā.
I tried it with the management of relations in the studio but I do not find a solution here.
Thanks for the support
You should be able to do this through Logic Hooks.
You can find how to set up a logic hook from the SugarCRM dev guide: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Logic_Hooks/Introduction/
I also made a post detailing how to create a logic hook here: https://suitecrm.com/forum/advanced-opensales-workflow-portal-support/6307-custom-action#22654
If you need more assistance with this, could you please clarify what you want to do further?
i.e: How the relate field should function or how the Users Module relates to the module with the field on it.
Hi John, thanks for your reply.
I understand that we need to write some code. The references to the pages youāve written are not complete and are not links.
I try to explain what I need to do:
In Accounts module I created a field called āagente_cā . This is a field type Relate related to user table (see attached picture 1).
When I go to the Accounts module, I create new account I wish that field was already filled with the name of the connected user. It should work exactly how the Assigned To field (see image 2 attached)
Thanks for your support, I hope I have explained well my request.
Not sure how that happened to the links in the previous post, but I have edited them so they are working now. Thanks for letting me know
Is there any reason you are not using the āAssigned toā field?
Also, To clarify, By " the connected user." do you mean the user that created the record? Or do you wish for āagente_cā to have the same value as āAssigned Toā?
Yes, I want the name of the user who created the record.
If possible I would like this read-only field for all users, while only the administrator can modify this field.
Thank you
Hi John, you had the time to look how to solve my problem?
Thank you
Hi AchLive,
I havenāt looked into it in great depth yet,
but if you create a logic hook, inside the Function in the hook you could have a line similar to
$bean -> agente_c = $current_user->id;
Whether it works or not will depend on how you have built your Logic hook, but this should set the agente_c field to the current user. (i.e, the creator of the record)
You will also have to do a Quick Repair & Rebuild if you edit/create a logic hook.
Thanks for the reply.
Will you be able to create me the files that serve?
Iām no expert programming. I also watched the links youāve written above, but it is not very clear to me how to act.
Maybe if you send me the files needed to hook logic in the coming times for me it will certainly be more clear.
I hope in your help and you understand my difficulties.
Thank you
Hi John,
there are chances that you can help me?
Excuse me if I ask again but are not able to make that change you explained.
Thank you
Navigate to /custom/modules/Accounts/logic_hooks.php
In this file, enter on line 10, beneath $hook_array[ābefore_saveā] = Array();
$hook_array[ ābefore_saveā ][] = array(79, āassign agenteā, ācustom/modules/Accounts/agenteAssign.phpā, āagenteClassā, āagenteFunctionā, );
Then, create a new file called agenteAssign.php at the location: /custom/modules/Accounts/
so it will be /custom/modules/Accounts/agenteAssign.php
in the agenteAssign.php file, enter:
<?php
class agenteClass {
function agenteFunc($bean, $event, $arguments) {
<CODE>
}
}
Where I have written , Is where you will enter the code for your functionality.
However, at the moment, I have been unable to investigate this and figure out the code to get this working.
I think guides such as: http://developer.sugarcrm.com/2012/03/23/howto-using-the-bean-instead-of-sql-all-the-time/
or: http://developer.sugarcrm.com/2012/11/12/getting-a-set-of-beans-by-conditions-without-sql/
may prove useful for this if you wish to give it a shot yourself.
Hi John,thanks for the reply.
I tried to follow the signs that thou hast written.
- I added this line
$hook_array[ 'before_save' ][] = array(79, 'assign agente', 'custom/modules/Accounts/agenteAssign.php', 'agenteClass', 'agenteFunction', );
in the file /custom/modules/Accounts/logic_hooks.php
- I created the file agenteAssign.php in the folder /custom/modules/Accounts/ and I wrote the following code in the file
<?php
class agenteClass {
function agenteFunc($bean, $event, $arguments) {
$bean -> agente_c = $current_user->id;
}
}
Where did you write I replaced with the code you gave me suggested in the post. Unfortunately I do not know what else to write because Iām not a programmer and link you sent me for me do not help.
The result is that it does not work and I do not know how. If you want to help you should give me the complete code.
Unfortunately, it is my limit, Iām not a programmer . If you do not have time to help me thank you for the suggestions you have given me.
Thanks