I am trying to add the following functionality to a SugarCRM detail page:
- When a button is clicked, a popup is displayed with a list of values loaded from an external service. The user can then manipulate the contents of the popup.
- When "Submit" is clicked on the popup, the record (bean) is updated with this changed data.
So far I've managed to add a button (I discuss it in this question Adding a button with custom JavaScript in SugarCRM 6.5) the usual Sugar way by adding it to detailviewdefs.php.
But instead of the button having a 'soap' field in its definition, 'soap' => 'CaseButtons/Approve'
I hooked up a JavaScript function to the button which does a jQuery ajax call and displays a popup.
Creating a random php file in my SugarCRM structure and then trying to call it would end up in 403 Forbidden. But I did manage to call a function I made in the controller class:
$ajax( { url: "?module=Cases&action=GetQuestions" ...
I was able to pass parameters and get a response to this call. All seemed well.
Then I noticed in the debugger, that the $this->bean
property is not populated in my function. The object is set, but except for field_key
(which is set to some guid) no other fields contain a value (all nulls or empty arrays) including the id. I have checked existing functions, and the fields in the bean are populated.
For my first call which gathers the information this is not a problem, but for the second call that is supposed to save the bean this is a huge problem.
I realize this is probably caused by me not using the standard 'soap' way to access the controller. But I can't imagine how I could create a popup with custom data and behavior that way.
Is there a way to make sure the bean is loaded when my function runs? Can I perhaps load it manually? I have the bean's id at my disposal (I send it from the UI). Would this break the normal Sugar functionality regarding saving beans (pre-, post-save hooks etc)
Or is there a way I can call the Sugar SOAP from JavaScript? I was thinking the "Submit" button could call the SOAP (since it's the only one that really needs it).