Subject
Challenge
The reason for this is the following. The relation between appointment (Meeting) and appointment owner (User) is a many-to-many relationship, which is stored in the table meetings_users
. But this table also holds the information about appointment accept status in the field accept_status
. By the way, same is valid for appointment-contact relationship, it will be meetings_contacts table, but I will focus on appointment owner only.
accept_status
field and searching for a solution has turned out to be challenging.Platform/Tools
Nothing new here:
- SugarCRM CE (Community Edition) version 6.5.16
- ActiveState perl (v5.14.2) on Windows 7
- And also one nice perl module Net::SugarCRM found on CPAN (version 2.17738).
Solution
Modifying Meetings vardefs
vardefs.php
file for Meetings module contains the following declaration for users
field:... 'users' => array ( 'name' => 'users', 'type' => 'link', 'relationship' => 'meetings_users', 'source'=>'non-db', 'vname'=>'LBL_USERS', ), ...
meetings_users
relationship. But this fragment doesn’t declare any additional attributes on this link (relationship) and this is why modifying these attributes is not working.SUGAR_ROOT/custom/Extension/modules/Meetings/Ext/Vardefs/
. Please note that this location is very important. File name seems to be less important as explained in some tutorials on the Web. Let’s name it vardefs.ext.php
:... $dictionary['Meeting']['fields']['users']['rel_fields'] = array( 'accept_status' => array( 'type' => 'enum', 'options' => 'dom_meeting_accept_status', ), ); ...
accept_status
. This will make existing code in SUGAR_ROOT/service/core/SoapHelperWebService.php
to update relationship attribute.... 'users' => array ( 'name' => 'users', 'type' => 'link', 'relationship' => 'meetings_users', 'source'=>'non-db', 'vname'=>'LBL_USERS', 'rel_fields' => array( 'accept_status' => array( 'type' => 'enum', 'options' => 'dom_meeting_accept_status', ), ), ), ...
enum
type for the accept_status
attribute and the values are defined in the drop-down list dom_meeting_accept_status
, which you can edit in SugarCRM administration interface. I observed also that it is possible to assign values, different from these in this drop-down list, but was too lazy to further investigate this.Re-writing client side code
The rest was easy. I again used my perl module Net::SugarCRM::Links (see “Create appointments (meetings) in SugarCRM via REST and perl“) and my code looked like this:
... my $user_link_entry = { accept_status => { 'name' => 'accept_status', 'value' => 'accept' } }; $out = $s->create_module_links('Meetings',$meeting_id,'users',[$user_id],$user_link_entry); ...
accept_status
attribute has to be constructed in a bit complex way, as a name-value pair. I don’t know if there is any explanation for this, in my case it worked and I was satisfied.Discussion
Now my appointments are created via Web service and they are already accepted by myself. I implemented this only for accept_status
attribute, but one could also do it for required
attribute and also for appointment participants (Contacts).
rel_fields
. So, to modify any other many-to-many relationships with attributes vardef customisation will be needed as well.